Class: Coercible::Coercer::Hash
- Defined in:
- lib/project/coercer/hash.rb
Overview
Coerce Hash values
Constant Summary collapse
- TIME_SEGMENTS =
[ :year, :month, :day, :hour, :min, :sec ].freeze
Constants inherited from Object
Object::COERCION_METHOD_REGEXP
Constants included from Options
Constants included from TypeLookup
Instance Attribute Summary
Attributes inherited from Object
Instance Method Summary collapse
-
#to_date(value) ⇒ Date
private
Creates a Date instance from a Hash.
-
#to_datetime(value) ⇒ DateTime
private
Creates a DateTime instance from a Hash.
-
#to_time(value) ⇒ Time
private
Creates a Time instance from a Hash.
Methods inherited from Object
#coerced?, #initialize, #inspect, #to_array, #to_hash, #to_integer, #to_string
Methods included from Options
#accept_options, #accepted_options, extended, #options
Methods included from TypeLookup
Constructor Details
This class inherits a constructor from Coercible::Coercer::Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Coercible::Coercer::Object
Instance Method Details
#to_date(value) ⇒ Date
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a Date instance from a Hash
Valid keys are: :year, :month, :day, :hour
34 35 36 |
# File 'lib/project/coercer/hash.rb', line 34 def to_date(value) ::Date.new(*extract(value).first(3)) end |
#to_datetime(value) ⇒ DateTime
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a DateTime instance from a Hash
Valid keys are: :year, :month, :day, :hour, :min, :sec
47 48 49 |
# File 'lib/project/coercer/hash.rb', line 47 def to_datetime(value) ::DateTime.new(*extract(value)) end |
#to_time(value) ⇒ Time
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a Time instance from a Hash
Valid keys are: :year, :month, :day, :hour, :min, :sec
21 22 23 |
# File 'lib/project/coercer/hash.rb', line 21 def to_time(value) ::Time.local(*extract(value)) end |