Class: Alchemist::CompoundMeasurement
- Inherits:
-
Object
- Object
- Alchemist::CompoundMeasurement
- Includes:
- Comparable
- Defined in:
- lib/alchemist/compound_measurement.rb
Instance Attribute Summary collapse
-
#denominators ⇒ Object
Returns the value of attribute denominators.
-
#numerators ⇒ Object
Returns the value of attribute numerators.
Instance Method Summary collapse
- #*(value) ⇒ Object
- #<=>(other) ⇒ Object
-
#initialize(numerator) ⇒ CompoundMeasurement
constructor
A new instance of CompoundMeasurement.
Constructor Details
#initialize(numerator) ⇒ CompoundMeasurement
Returns a new instance of CompoundMeasurement.
6 7 8 9 10 |
# File 'lib/alchemist/compound_measurement.rb', line 6 def initialize(numerator) @coefficient = numerator.value @numerators = [numerator / @coefficient] @denominators = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Attribute Details
#denominators ⇒ Object
Returns the value of attribute denominators.
4 5 6 |
# File 'lib/alchemist/compound_measurement.rb', line 4 def denominators @denominators end |
#numerators ⇒ Object
Returns the value of attribute numerators.
4 5 6 |
# File 'lib/alchemist/compound_measurement.rb', line 4 def numerators @numerators end |
Instance Method Details
#*(value) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/alchemist/compound_measurement.rb', line 20 def *(value) case value when Numeric @coefficient *= value self when Alchemist::Measurement @numerators << value return consolidate end end |
#<=>(other) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/alchemist/compound_measurement.rb', line 12 def <=> other if @coefficient == other.coefficient [@numerators, @denominators] <=> [other.numerators, other.denominators] else @coefficient <=> other.coefficient end end |