Class: Timespan
Constant Summary collapse
Class Method Summary collapse
-
.demongoize(object) ⇒ Timespan
Deserialize a Timespan given the hash stored by Mongodb.
-
.evolve(object) ⇒ Object
Converts the object that was supplied to a criteria and converts it into a database friendly form.
-
.mongoize(object) ⇒ Hash
Serialize a Timespan or a Hash (with Timespan units) or a Duration in some form to a BSON serializable type.
Instance Method Summary collapse
-
#mongoize ⇒ Hash
Serialize a Timespan or a Hash (with Timespan units) or a Duration in some form to a BSON serializable type.
Class Method Details
.demongoize(object) ⇒ Timespan
Deserialize a Timespan given the hash stored by Mongodb
37 38 39 40 41 42 43 44 45 |
# File 'lib/timespan/mongoid/mongoid_3x.rb', line 37 def demongoize(object) return if !object case object when Hash ::Timespan.new :from => Serializer.from(object), :to => Serializer.to(object) else ::Timespan.new object end end |
.evolve(object) ⇒ Object
Converts the object that was supplied to a criteria and converts it into a database friendly form.
49 50 51 52 53 54 |
# File 'lib/timespan/mongoid/mongoid_3x.rb', line 49 def evolve(object) case object when Timespan then object.mongoize else object end end |
.mongoize(object) ⇒ Hash
Serialize a Timespan or a Hash (with Timespan units) or a Duration in some form to a BSON serializable type.
23 24 25 26 27 28 29 30 31 |
# File 'lib/timespan/mongoid/mongoid_3x.rb', line 23 def mongoize object case object when Timespan then object.mongoize when Hash ::Timespan.new object else object end end |
Instance Method Details
#mongoize ⇒ Hash
Serialize a Timespan or a Hash (with Timespan units) or a Duration in some form to a BSON serializable type.
11 12 13 |
# File 'lib/timespan/mongoid/mongoid_3x.rb', line 11 def mongoize {:from => Serializer.serialize_time(start_time), :to => Serializer.serialize_time(end_time), :duration => duration.total } end |