Class: Restspec::Schema::Types::DateType
- Defined in:
- lib/restspec/schema/types/date_type.rb
Constant Summary collapse
- DATE_FORMAT =
/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/
Instance Method Summary collapse
Methods inherited from BasicType
#initialize, #of, #to_s, #totally_valid?, #|
Constructor Details
This class inherits a constructor from Restspec::Schema::Types::BasicType
Instance Method Details
#example_for(attribute) ⇒ Object
5 6 7 |
# File 'lib/restspec/schema/types/date_type.rb', line 5 def example_for(attribute) Faker::Date.between(1.month.ago, Date.today).to_s end |
#valid?(attribute, value) ⇒ Boolean
9 10 11 12 13 14 |
# File 'lib/restspec/schema/types/date_type.rb', line 9 def valid?(attribute, value) return false unless value.present? return false unless value.match(DATE_FORMAT).present? year, month, day = value.split('-').map &:to_i Date.valid_date?(year, month, day) end |