module Mongoid::Fields::Timespan::Methods

protected

Public Instance Methods

asap(hash) click to toggle source
# File lib/timespan/mongoid.rb, line 42
def asap hash
  asap_value = hash['asap'] || hash[:asap]
  raise ArgumentError, ":asap is nil, #{hash.inspect}" if ![true, false, nil].include? asap_value
  asap_value
end
deserialize_time(millisecs) click to toggle source
# File lib/timespan/mongoid.rb, line 53
def deserialize_time millisecs
  raise ArgumentError, "Can't deserialize time from nil" if millisecs.nil?
  Time.at millisecs
end
from(hash) click to toggle source
# File lib/timespan/mongoid.rb, line 30
def from hash
  from_value = hash['from'] || hash[:from]
  raise ArgumentError, ":from is nil, #{hash.inspect}" if from_value.nil?
  deserialize_time from_value
end
serialize_time(time) click to toggle source
# File lib/timespan/mongoid.rb, line 48
def serialize_time time
  raise ArgumentError, "Can't serialize time from nil" if time.nil?
  time.to_i
end
to(hash) click to toggle source
# File lib/timespan/mongoid.rb, line 36
def to hash
  to_value = hash['to'] || hash[:to]
  raise ArgumentError, ":to is nil, #{hash.inspect}" if to_value.nil?
  deserialize_time to_value
end