Class: Convertable::Measure
- Inherits:
-
Object
- Object
- Convertable::Measure
- Defined in:
- lib/convertable/measure.rb
Direct Known Subclasses
Convertable::Measures::Area, Convertable::Measures::Money, Convertable::Measures::MoneyPerAreaPerPeriod, Convertable::Measures::MoneyPerPeriod, Convertable::Measures::Period
Instance Attribute Summary collapse
-
#magnitude ⇒ Object
readonly
Returns the value of attribute magnitude.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Instance Method Summary collapse
- #==(other_measure) ⇒ Object
- #in(new_unit) ⇒ Object
-
#initialize(magnitude, unit) ⇒ Measure
constructor
A new instance of Measure.
Constructor Details
#initialize(magnitude, unit) ⇒ Measure
Returns a new instance of Measure.
5 6 7 8 |
# File 'lib/convertable/measure.rb', line 5 def initialize(magnitude, unit) @magnitude = magnitude @unit = unit end |
Instance Attribute Details
#magnitude ⇒ Object (readonly)
Returns the value of attribute magnitude.
3 4 5 |
# File 'lib/convertable/measure.rb', line 3 def magnitude @magnitude end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
3 4 5 |
# File 'lib/convertable/measure.rb', line 3 def unit @unit end |
Instance Method Details
#==(other_measure) ⇒ Object
17 18 19 |
# File 'lib/convertable/measure.rb', line 17 def ==(other_measure) magnitude == other_measure.magnitude && unit == other_measure.unit end |
#in(new_unit) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/convertable/measure.rb', line 10 def in(new_unit) return self if new_unit == unit new_magnitude = unit.convert_to(magnitude, new_unit) self.class.new(new_magnitude, new_unit) end |