Class: Parameters::Types::Date

Inherits:
Object show all
Defined in:
lib/parameters/types/date.rb

Direct Known Subclasses

DateTime

Class Method Summary collapse

Methods inherited from Object

#===, ===, to_ruby

Methods inherited from Type

#<, #<=, #==, ===, #===, #coerce, #to_ruby, to_ruby

Class Method Details

.coerce(value) ⇒ ::Date

Coerces a value into a Date.

Parameters:

  • value (::String, #to_date)

    The value to coerce.

Returns:

  • (::Date)

    The coerced Date.



18
19
20
21
22
23
24
# File 'lib/parameters/types/date.rb', line 18

def self.coerce(value)
  if value.respond_to?(:to_date)
    value.to_date
  else
    ::Date.parse(value.to_s)
  end
end