Class: MetadataPresenter::DateValidator
- Inherits:
-
BaseValidator
- Object
- BaseValidator
- MetadataPresenter::DateValidator
- Defined in:
- app/validators/metadata_presenter/date_validator.rb
Direct Known Subclasses
Constant Summary collapse
- DATE_STRING_VALIDATIONS =
%w[date_after date_before].freeze
- YEAR_LOWER_BOUND =
1000
- YEAR_UPPER_BOUND =
3000
Instance Attribute Summary
Attributes inherited from BaseValidator
Instance Method Summary collapse
Methods inherited from BaseValidator
#allow_blank?, #custom_error_message, #default_error_message, #error_key, #error_message_hash, #initialize, #schema_key, #user_answer, #valid?
Constructor Details
This class inherits a constructor from MetadataPresenter::BaseValidator
Instance Method Details
#invalid_answer? ⇒ Boolean
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/validators/metadata_presenter/date_validator.rb', line 7 def invalid_answer? date = Date.civil( user_answer.year.to_i, user_answer.month.to_i, user_answer.day.to_i ) # additional validations that `#civil` will not raise as errors return true if date.year < YEAR_LOWER_BOUND return true if date.year > YEAR_UPPER_BOUND false rescue Date::Error true end |
#validation_value ⇒ Object
21 22 23 24 25 |
# File 'app/validators/metadata_presenter/date_validator.rb', line 21 def validation_value return unless schema_key.in?(DATE_STRING_VALIDATIONS) Date.parse(component.validation[schema_key]).strftime('%d %m %Y') end |