Class: Lite::Measurements::Mass
- Includes:
- Helpers::ConversionHelper, Helpers::ShiftHelper
- Defined in:
- lib/lite/measurements/mass.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#convert(from:, to:) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Lite::Measurements::Base
Instance Method Details
#convert(from:, to:) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lite/measurements/mass.rb', line 21 def convert(from:, to:) assert_all_valid_keys!(from, to, all_keys) if equal_units?(from, to) amount elsif shift_between_imperical_units?(from, to) shift_units(amount, type: IMPERICAL_UNITS, from: from, to: to) elsif shift_between_metric_units?(from, to) shift_units(amount, type: METRIC_UNITS, from: from, to: to) elsif convert_to_metric_units?(from, to) convert_to_metric_units(amount, from: from, convert_to: :ounces, convert_from: :grams, to: to) else convert_to_imperical_units(amount, from: from, convert_to: :grams, convert_from: :ounces, to: to) end end |