Class: Virtus::Coercion::Hash
- Inherits:
-
Object
- Object
- Virtus::Coercion
- Object
- Virtus::Coercion::Hash
- Defined in:
- lib/virtus/coercion/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 TypeLookup
Class 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
to_array, to_hash, to_integer, to_string
Methods inherited from Virtus::Coercion
Methods included from TypeLookup
#determine_type, extended, #primitive
Methods included from Options
#accept_options, #accepted_options, #options
Class 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
32 33 34 |
# File 'lib/virtus/coercion/hash.rb', line 32 def self.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
45 46 47 |
# File 'lib/virtus/coercion/hash.rb', line 45 def self.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
19 20 21 |
# File 'lib/virtus/coercion/hash.rb', line 19 def self.to_time(value) ::Time.local(*extract(value)) end |