Class: QDM::Ratio
- Inherits:
-
Object
- Object
- QDM::Ratio
- Defined in:
- app/models/qdm/basetypes/ratio.rb
Overview
Represents a Ratio
Instance Attribute Summary collapse
-
#denominator ⇒ Object
Returns the value of attribute denominator.
-
#numerator ⇒ Object
Returns the value of attribute numerator.
Class Method Summary collapse
-
.demongoize(object) ⇒ Object
Get the object as it was stored in the database, and instantiate this custom class from it.
-
.evolve(object) ⇒ Object
Converts the object that was supplied to a criteria and converts it into a database friendly form.
-
.mongoize(object) ⇒ Object
Takes any possible object and converts it to how it would be stored in the database.
Instance Method Summary collapse
-
#initialize(numerator, denominator) ⇒ Ratio
constructor
Numerator and denominator are required.
-
#mongoize ⇒ Object
Converts an object of this instance into a database friendly value.
Constructor Details
#initialize(numerator, denominator) ⇒ Ratio
Numerator and denominator are required
7 8 9 10 |
# File 'app/models/qdm/basetypes/ratio.rb', line 7 def initialize(numerator, denominator) @numerator = numerator @denominator = denominator end |
Instance Attribute Details
#denominator ⇒ Object
Returns the value of attribute denominator.
4 5 6 |
# File 'app/models/qdm/basetypes/ratio.rb', line 4 def denominator @denominator end |
#numerator ⇒ Object
Returns the value of attribute numerator.
4 5 6 |
# File 'app/models/qdm/basetypes/ratio.rb', line 4 def numerator @numerator end |
Class Method Details
.demongoize(object) ⇒ Object
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 2 elements used in mongoize, i.e. [ numerator, denominator ].
23 24 25 26 27 28 |
# File 'app/models/qdm/basetypes/ratio.rb', line 23 def demongoize(object) return nil unless object object = object.symbolize_keys QDM::Ratio.new(object[:numerator], object[:denominator]) if object.is_a?(Hash) end |
.evolve(object) ⇒ Object
Converts the object that was supplied to a criteria and converts it into a database friendly form.
45 46 47 48 49 50 |
# File 'app/models/qdm/basetypes/ratio.rb', line 45 def evolve(object) case object when QDM::Ratio then object.mongoize else object end end |
.mongoize(object) ⇒ Object
Takes any possible object and converts it to how it would be stored in the database.
32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/qdm/basetypes/ratio.rb', line 32 def mongoize(object) case object when nil then nil when QDM::Ratio then object.mongoize when Hash object = object.symbolize_keys QDM::Ratio.new(object[:numerator], object[:denominator]).mongoize else object end end |
Instance Method Details
#mongoize ⇒ Object
Converts an object of this instance into a database friendly value.
13 14 15 |
# File 'app/models/qdm/basetypes/ratio.rb', line 13 def mongoize { numerator: @numerator, denominator: @denominator, _type: 'QDM::Ratio' } end |