Class: Coercible::Coercer::Hash

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

Options::Undefined

Constants included from TypeLookup

TypeLookup::TYPE_FORMAT

Instance Attribute Summary

Attributes inherited from Object

#coercers

Instance Method Summary collapse

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

#determine_type, extended

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

Parameters:

Returns:



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

Parameters:

Returns:



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

Parameters:

Returns:



21
22
23
# File 'lib/project/coercer/hash.rb', line 21

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