Class: EasyJSONMatcher::DateValidator
- Defined in:
- lib/easy_json_matcher/date_validator.rb
Constant Summary collapse
- DEFAULT_DATE_FORMAT =
"%Y-%m-%d"
Instance Attribute Summary collapse
-
#date_format ⇒ Object
readonly
Returns the value of attribute date_format.
-
#string_validator ⇒ Object
readonly
Returns the value of attribute string_validator.
Attributes inherited from Validator
Instance Method Summary collapse
- #_validate ⇒ Object
- #_validate_as_date ⇒ Object
- #_validate_as_string ⇒ Object
-
#initialize(opts = {}) ⇒ DateValidator
constructor
A new instance of DateValidator.
Methods inherited from Validator
Constructor Details
#initialize(opts = {}) ⇒ DateValidator
Returns a new instance of DateValidator.
8 9 10 11 12 |
# File 'lib/easy_json_matcher/date_validator.rb', line 8 def initialize(opts = {}) super(opts) @date_format = opts[:format] @string_validator = ValidatorFactory.create({type: :string}) end |
Instance Attribute Details
#date_format ⇒ Object (readonly)
Returns the value of attribute date_format.
5 6 7 |
# File 'lib/easy_json_matcher/date_validator.rb', line 5 def date_format @date_format end |
#string_validator ⇒ Object (readonly)
Returns the value of attribute string_validator.
5 6 7 |
# File 'lib/easy_json_matcher/date_validator.rb', line 5 def string_validator @string_validator end |
Instance Method Details
#_validate ⇒ Object
14 15 16 |
# File 'lib/easy_json_matcher/date_validator.rb', line 14 def _validate _validate_as_string && _validate_as_date end |
#_validate_as_date ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/easy_json_matcher/date_validator.rb', line 22 def _validate_as_date require 'date' begin Date.strptime(content, date_format) rescue ArgumentError false end end |
#_validate_as_string ⇒ Object
18 19 20 |
# File 'lib/easy_json_matcher/date_validator.rb', line 18 def _validate_as_string string_validator.valid? content end |