Class: MetadataPresenter::DateValidator

Inherits:
BaseValidator show all
Defined in:
app/validators/metadata_presenter/date_validator.rb

Direct Known Subclasses

DateAfterValidator, DateBeforeValidator

Constant Summary collapse

DATE_STRING_VALIDATIONS =
%w[date_after date_before].freeze

Instance Attribute Summary

Attributes inherited from BaseValidator

#component, #page_answers

Instance Method Summary collapse

Methods inherited from BaseValidator

#allow_blank?, #custom_error_message, #default_error_message, #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

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
13
14
# File 'app/validators/metadata_presenter/date_validator.rb', line 5

def invalid_answer?
  Date.strptime(
    "#{user_answer.year}-#{user_answer.month}-#{user_answer.day}",
    '%Y-%m-%d'
  )

  false
rescue Date::Error
  true
end

#validation_valueObject



16
17
18
19
20
# File 'app/validators/metadata_presenter/date_validator.rb', line 16

def validation_value
  return unless schema_key.in?(DATE_STRING_VALIDATIONS)

  Date.parse(component.validation[schema_key]).strftime('%d %m %Y')
end