Class: Convertable::Units::ComposedUnit
- Inherits:
-
Object
- Object
- Convertable::Units::ComposedUnit
- Defined in:
- lib/convertable/units.rb
Instance Attribute Summary collapse
-
#dividing_units ⇒ Object
readonly
Returns the value of attribute dividing_units.
-
#multiplying_unit ⇒ Object
readonly
Returns the value of attribute multiplying_unit.
Instance Method Summary collapse
- #==(other_composed_unit) ⇒ Object
- #convert_to(magnitude, new_composed_unit) ⇒ Object
-
#initialize(units) ⇒ ComposedUnit
constructor
A new instance of ComposedUnit.
- #to_json ⇒ Object
Constructor Details
#initialize(units) ⇒ ComposedUnit
Returns a new instance of ComposedUnit.
85 86 87 |
# File 'lib/convertable/units.rb', line 85 def initialize(units) , *@dividing_units = units.split("/").map { |unit| Convertable::Units.find(unit) } end |
Instance Attribute Details
#dividing_units ⇒ Object (readonly)
Returns the value of attribute dividing_units.
83 84 85 |
# File 'lib/convertable/units.rb', line 83 def dividing_units @dividing_units end |
#multiplying_unit ⇒ Object (readonly)
Returns the value of attribute multiplying_unit.
83 84 85 |
# File 'lib/convertable/units.rb', line 83 def end |
Instance Method Details
#==(other_composed_unit) ⇒ Object
95 96 97 98 |
# File 'lib/convertable/units.rb', line 95 def ==(other_composed_unit) == other_composed_unit. && dividing_units == other_composed_unit.dividing_units end |
#convert_to(magnitude, new_composed_unit) ⇒ Object
89 90 91 92 93 |
# File 'lib/convertable/units.rb', line 89 def convert_to(magnitude, new_composed_unit) raise UnsupportedConversion unless new_composed_unit.is_a?(ComposedUnit) magnitude * conversion_factor_to(new_composed_unit) end |
#to_json ⇒ Object
100 101 102 |
# File 'lib/convertable/units.rb', line 100 def to_json name end |