class Mongoid::Fields::Serializer
Attributes
end_field[W]
start_field[W]
Public Class Methods
end_field()
click to toggle source
# File lib/timespan/mongoid.rb, line 22 def end_field @end_field || :to end
instantiate(name, options = {})
click to toggle source
Calls superclass method
# File lib/timespan/mongoid/mongoid_2x.rb, line 7 def self.instantiate(name, options = {}) super end
start_field()
click to toggle source
# File lib/timespan/mongoid.rb, line 18 def start_field @start_field || :from end
Public Instance Methods
deserialize(hash)
click to toggle source
serialize(value)
click to toggle source
Serialize a Timespan
or a Hash
(with Timespan
units) or a Duration in some form to a BSON serializable type.
@param [Timespan, Hash
, Integer, String] value @return [Hash] Timespan
in seconds
# File lib/timespan/mongoid/mongoid_2x.rb, line 25 def serialize(value) return if value.blank? timespan = case value when ::Timespan value else ::Timespan.new(value) end {:from => serialize_time(timespan.start_time), :to => serialize_time(timespan.end_time.to_i), :duration => timespan.duration.total } end