Class: OpenActive::Validators::NumberValidator
- Inherits:
-
BaseValidator
- Object
- BaseValidator
- OpenActive::Validators::NumberValidator
- Defined in:
- lib/openactive/validators/number_validator.rb
Instance Method Summary collapse
-
#coerce(value) ⇒ float
Coerce given value to the type the validator is validating against.
-
#run(value) ⇒ Boolean
Run validation on the given value.
Methods inherited from BaseValidator
Instance Method Details
#coerce(value) ⇒ float
Coerce given value to the type the validator is validating against. PLEASE NOTE: no checks are performed on the given value. It is therefore recommended to call the “run” method first before this.
10 11 12 |
# File 'lib/openactive/validators/number_validator.rb', line 10 def coerce(value) BigDecimal(value.to_s) end |
#run(value) ⇒ Boolean
Run validation on the given value.
18 19 20 21 22 23 |
# File 'lib/openactive/validators/number_validator.rb', line 18 def run(value) BigDecimal(value.to_s) true rescue ArgumentError => _e false end |