Sha256: fd1d8fcd32fcd53eeea3766177e007275cb39be2f4c7e022376ca608ed6ccbaf

Contents?: true

Size: 405 Bytes

Versions: 3

Compression:

Stored size: 405 Bytes

Contents

module UnitsConverter
  class QuantityWithUnit
    def initialize(quantity, unit)
      unit = ActiveSupport::Inflector.singularize(unit)
      @quantity_in_metres = UnitsConverter::CONVERSIONS_TO_METRES.fetch(unit) * quantity
    end

    def to(unit)
      unit = ActiveSupport::Inflector.singularize(unit)
      @quantity_in_metres / UnitsConverter::CONVERSIONS_TO_METRES.fetch(unit)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
units_converter-0.0.3 lib/units_converter/quantity_with_unit.rb
units_converter-0.0.2 lib/units_converter/quantity_with_unit.rb
units_converter-0.0.1 lib/units_converter/quantity_with_unit.rb