Class: OpenActive::Validators::EnumValidator
- Inherits:
-
BaseValidator
- Object
- BaseValidator
- OpenActive::Validators::EnumValidator
- Defined in:
- lib/openactive/validators/enum_validator.rb
Instance Method Summary collapse
-
#coerce(value) ⇒ int
Coerce enum url to the enum instance.
-
#initialize(classname) ⇒ EnumValidator
constructor
A new instance of EnumValidator.
-
#run(value) ⇒ Boolean
Run validation on the given value.
Methods inherited from BaseValidator
Constructor Details
#initialize(classname) ⇒ EnumValidator
Returns a new instance of EnumValidator.
4 5 6 |
# File 'lib/openactive/validators/enum_validator.rb', line 4 def initialize(classname) @classname = classname end |
Instance Method Details
#coerce(value) ⇒ int
Coerce enum url to the enum instance
12 13 14 15 16 |
# File 'lib/openactive/validators/enum_validator.rb', line 12 def coerce(value) return value if value.is_a?(classname) classname.find_by_value(value) end |
#run(value) ⇒ Boolean
Run validation on the given value.
22 23 24 25 26 |
# File 'lib/openactive/validators/enum_validator.rb', line 22 def run(value) return true if value.is_a?(classname) classname.find_by_value(value) end |