Sha256: b93e1e519b958181022b442fdccff81ede8d85987d5e28e25dd9dca5b2b1fdf4
Contents?: true
Size: 1.67 KB
Versions: 2
Compression:
Stored size: 1.67 KB
Contents
module QDM # Represents an Interval class Interval attr_accessor :low, :high, :lowClosed, :highClosed # Low and high are required (at minimum). def initialize(low, high, lowClosed = true, highClosed = true) @low = low @high = high @lowClosed = lowClosed @highClosed = highClosed end # Converts an object of this instance into a database friendly value. def mongoize { low: @low, high: @high, lowClosed: @lowClosed, highClosed: @highClosed, _type: 'QDM::Interval' } end class << self # Get the object as it was stored in the database, and instantiate # this custom class from it. # # The array elements in demongoize are the same 5 elements used in mongoize, i.e. # [ low, high ]. def demongoize(object) return nil unless object object = object.symbolize_keys QDM::Interval.new(object[:low], object[:high], object[:lowClosed], object[:highClosed]) if object.is_a?(Hash) end # Takes any possible object and converts it to how it would be # stored in the database. def mongoize(object) case object when nil then nil when QDM::Interval then object.mongoize when Hash object = object.symbolize_keys QDM::Interval.new(object[:low], object[:high], object[:lowClosed], object[:highClosed]).mongoize else object end end # Converts the object that was supplied to a criteria and converts it # into a database friendly form. def evolve(object) case object when QDM::Interval then object.mongoize else object end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cqm-models-0.7.7 | app/models/qdm/basetypes/interval.rb |
cqm-models-0.7.6 | app/models/qdm/basetypes/interval.rb |