Module: Rapid::Common::Types::Validators

Included in:
Model::ComponentCreator, Model::Item
Defined in:
lib/ury_rapid/common/types.rb

Overview

Validators for the Rapid type enumerators.

Class Method Summary collapse

Class Method Details

.invalidObject


39
40
41
# File 'lib/ury_rapid/common/types.rb', line 39

def invalid
  fail(Rapid::Common::Exceptions::InvalidPayload)
end

.validate_marker(input) ⇒ Object


31
32
33
34
35
36
# File 'lib/ury_rapid/common/types.rb', line 31

def validate_marker(input)
  # Why is the input changed to a string?
  # Because Integer('0.3') raises an error, but Integer(0.3) doesn't.
  # Integer('3') and Integer(3), however, both return 3.
  Integer(input.to_s).tap { |marker| invalid if marker < 0 }
end

.validate_symbol(input, range) ⇒ Object


21
22
23
# File 'lib/ury_rapid/common/types.rb', line 21

def validate_symbol(input, range)
  input.to_sym.tap { |symbol| invalid unless range.include?(symbol) }
end

.validate_volume(input) ⇒ Object


26
27
28
# File 'lib/ury_rapid/common/types.rb', line 26

def validate_volume(input)
  [0.0, Float(input), 1.0].sort[1]
end