Class: VanillaValidator::Rules::Date

Inherits:
BaseRule
  • Object
show all
Defined in:
lib/vanilla_validator/rules/date.rb

Instance Attribute Summary

Attributes inherited from BaseRule

#attribute, #parameters, #value

Instance Method Summary collapse

Methods inherited from BaseRule

#initialize

Constructor Details

This class inherits a constructor from VanillaValidator::Rules::BaseRule

Instance Method Details

#failure_messageObject



14
15
16
# File 'lib/vanilla_validator/rules/date.rb', line 14

def failure_message
  I18n.t('date', attribute: attribute)
end

#valid?Boolean

Returns:



4
5
6
7
8
9
10
11
12
# File 'lib/vanilla_validator/rules/date.rb', line 4

def valid?
  begin
    ::Date.strptime(value, '%Y-%m-%d')
    true
  rescue
    # ArgumentError, TypeError

    false
  end
end