Sha256: a9c3710eab33346980fe41f24b84d153bb9bab21a8935e82e63f35388f3c929d

Contents?: true

Size: 452 Bytes

Versions: 2

Compression:

Stored size: 452 Bytes

Contents

module Restspec::Schema::Types
  class DateType < BasicType
    DATE_FORMAT = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/

    def example_for(attribute)
      Faker::Date.between(1.month.ago, Date.today).to_s
    end

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
restspec-0.0.4 lib/restspec/schema/types/date_type.rb
restspec-0.0.3 lib/restspec/schema/types/date_type.rb