Class: Convertio::Converter
- Inherits:
-
Object
- Object
- Convertio::Converter
- Defined in:
- lib/convertio.rb
Overview
This class validates input and performs conversion
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(value, from, to) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(value, from, to) ⇒ Converter
Returns a new instance of Converter.
95 96 97 98 99 100 101 102 |
# File 'lib/convertio.rb', line 95 def initialize(value, from, to) @value = value @from = from @to = to @from_unit = UNITS[@from] @to_unit = UNITS[@to] validate! end |
Instance Method Details
#convert ⇒ Object
104 105 106 |
# File 'lib/convertio.rb', line 104 def convert (@value * @from_unit[:per_base]) / @to_unit[:per_base].to_f end |