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.
84 85 86 |
# File 'lib/convertable/units.rb', line 84 def initialize(units) @multiplying_unit, *@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.
82 83 84 |
# File 'lib/convertable/units.rb', line 82 def dividing_units @dividing_units end |
#multiplying_unit ⇒ Object (readonly)
Returns the value of attribute multiplying_unit.
82 83 84 |
# File 'lib/convertable/units.rb', line 82 def @multiplying_unit end |
Instance Method Details
#==(other_composed_unit) ⇒ Object
94 95 96 97 |
# File 'lib/convertable/units.rb', line 94 def ==(other_composed_unit) == other_composed_unit. && dividing_units == other_composed_unit.dividing_units end |
#convert_to(magnitude, new_composed_unit) ⇒ Object
88 89 90 91 92 |
# File 'lib/convertable/units.rb', line 88 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
99 100 101 |
# File 'lib/convertable/units.rb', line 99 def to_json name end |