class Lite::Measurements::Length

Constants

CONVERTER
IMPERICAL_UNITS
METRIC_UNITS

Public Instance Methods

convert(from:, to:) click to toggle source

rubocop:disable Metrics/MethodLength, Layout/LineLength

# File lib/lite/measurements/length.rb, line 31
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: :inches, convert_from: :meters, to: to)
  else
    convert_to_imperical_units(amount, from: from, convert_to: :meters, convert_from: :inches, to: to)
  end
end