Class: Parameters::Types::Time

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

Class Method Summary collapse

Methods inherited from Object

#===, ===, to_ruby

Methods inherited from Type

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

Class Method Details

.coerce(value) ⇒ ::Time

Coerces a value into a Time object.

Parameters:

  • value (Integer, #to_time, #to_s)

    The value to coerce.

Returns:

  • (::Time)

    The coerced Time object.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/parameters/types/time.rb', line 18

def self.coerce(value)
  case value
  when Integer
    ::Time.at(value)
  else
    if value.respond_to?(:to_time)
      value.to_time
    else
      ::Time.parse(value.to_s)
    end
  end
end