Class: ChangeFinal::Different
- Inherits:
-
Object
- Object
- ChangeFinal::Different
- Includes:
- Singleton
- Defined in:
- lib/change_final.rb
Constant Summary collapse
- CONVERSIONS =
lookup table
{ kg: { pounds: 2.20462, stone: 0.157473, }, pounds: { kg: 0.453592, stone: 0.0714286 }, stone: { kg: 6.35029, pounds: 14 } }
Instance Method Summary collapse
Instance Method Details
#conversions(value, unit) ⇒ Object
30 31 32 33 34 |
# File 'lib/change_final.rb', line 30 def conversions(value, unit) CONVERSIONS[unit].keys.map do |other_unit| convert(value, unit, to: other_unit) end end |
#convert(value, from, to:) ⇒ Object
24 25 26 27 28 |
# File 'lib/change_final.rb', line 24 def convert(value, from, to:) raise ConversionError, "Value is not numeric" unless value.is_a? Numeric raise ConversionError, "Value #{value} is not positive" unless value >= 0 "#{value * conversion_ratio(from, to) }#{to.to_s}" end |