Sha256: 85ddc43e84e56e4a9a64cc069cb70615249e2e251ffc04757b80a25134348d59

Contents?: true

Size: 644 Bytes

Versions: 5

Compression:

Stored size: 644 Bytes

Contents

class Hash
  def __evolve_to_timespan__
    serializer = Mongoid::Fields::Timespan
    object = self
    # puts "evolve from: #{self}"
    ::Timespan.new :from => serializer.from(object), :to => serializer.to(object), asap: serializer.asap(object)
  end

  def __evolve_to_duration_range__
    range = Range.new (self['from'] || self[:from]), (self['to'] || self[:to])
    length = self['length'] || self[:length]
    clazz = case length.to_sym
    when :long 
      ::LongDurationRange
    when :short 
      ::ShortDurationRange
    else
      ::DurationRange
    end

    clazz.new range, (self['unit'] || self[:unit] || :seconds)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
timespan-0.6.0 lib/timespan/core_ext/hash.rb
timespan-0.5.9 lib/timespan/core_ext/hash.rb
timespan-0.5.7 lib/timespan/core_ext/hash.rb
timespan-0.5.6.1 lib/timespan/core_ext/hash.rb
timespan-0.5.6 lib/timespan/core_ext/hash.rb