lib/timespan/mongoid.rb in timespan-0.2.0 vs lib/timespan/mongoid.rb in timespan-0.2.1

- old
+ new

@@ -5,10 +5,14 @@ module Mongoid module Fields class Timespan include Mongoid::Fields::Serializable + def self.instantiate(name, options = {}) + super + end + # Deserialize a Timespan given the hash stored by Mongodb # # @param [Hash] Timespan as hash # @return [Timespan] deserialized Timespan def deserialize(timespan_hash) @@ -22,10 +26,12 @@ # @param [Timespan, Hash, Integer, String] value # @return [Hash] Timespan in seconds def serialize(value) return if value.blank? timespan = ::Timespan.new(value) - {:from => time_span.start_time, :to => time_span.end_time, :Timespan => time_span.Timespan} + {:from => timespan.start_time, :to => timespan.end_time, :duration => timespan.duration.total} end end end -end +end + +TimeSpan = Mongoid::Fields::Timespan \ No newline at end of file