Class: OpenActive::Validators::DateTimeValidator
- Inherits:
-
BaseValidator
- Object
- BaseValidator
- OpenActive::Validators::DateTimeValidator
- Defined in:
- lib/openactive/validators/date_time_validator.rb
Instance Method Summary collapse
-
#coerce(value) ⇒ mixed
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) ⇒ mixed
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 13 14 15 16 17 |
# File 'lib/openactive/validators/date_time_validator.rb', line 10 def coerce(value) return value if value.is_a?(::DateTime) # if it's a date/time object other than datetime, convert it (Date/Time) return value.to_datetime if value.respond_to?(:to_datetime) parse_date(value) end |
#run(value) ⇒ Boolean
Run validation on the given value.
23 24 25 26 27 28 29 |
# File 'lib/openactive/validators/date_time_validator.rb', line 23 def run(value) return true if value.is_a?(::DateTime) || value.respond_to?(:to_datetime) return false unless value.is_a?(String) !parse_date(value).nil? end |