Class: Virtus::Coercion::Hash

Inherits:
Object show all
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

TypeLookup::TYPE_FORMAT

Class Method Summary collapse

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

Parameters:

Returns:



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

Parameters:

Returns:



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

Parameters:

Returns:



19
20
21
# File 'lib/virtus/coercion/hash.rb', line 19

def self.to_time(value)
  ::Time.local(*extract(value))
end