Module: DataMapper::Property::Typecast::Time

Includes:
Numeric
Included in:
Date, DateTime, DataMapper::Property::Time
Defined in:
lib/dm-core/property/typecast/time.rb

Instance Method Summary collapse

Methods included from Numeric

#typecast_to_numeric

Instance Method Details

#extract_time(value) ⇒ Array

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.

Extracts the given args from the hash. If a value does not exist, it uses the value of Time.now.

Parameters:

  • value (Hash, #to_mash)

    value to extract time args from

Returns:

  • (Array)

    Extracted values



17
18
19
20
21
22
23
24
# File 'lib/dm-core/property/typecast/time.rb', line 17

def extract_time(value)
  mash = value.respond_to?(:to_mash) ? value.to_mash : DataMapper::Ext::Hash.to_mash(value)
  now  = ::Time.now

  [ :year, :month, :day, :hour, :min, :sec ].map do |segment|
    typecast_to_numeric(mash.fetch(segment, now.send(segment)), :to_i)
  end
end