Sha256: 313f5b6224cdd99da9649d94d11d713a9b42e2ba5276a6d151f25da4d1a3da7b

Contents?: true

Size: 775 Bytes

Versions: 1

Compression:

Stored size: 775 Bytes

Contents

require 'convert_unit/base'
require 'convert_unit/pre_process/volume/process'

module ConvertUnit
  class Volume < Base
    extend PreProcess::Volume
    UNITS_SYMBOL = load_units_symbol
    UNITS = load_available_units
    CONVERSION_RATE = load_conversion_rate

    attr_accessor :value, :unit

    def initialize(value, unit)
      unit_symbol = Volume::UNITS_SYMBOL[unit] || unit
      @conversion_rate_for_one_unit = Volume::CONVERSION_RATE
      super(value, unit_symbol, Volume::UNITS)
    end

    def to(c_unit)
      c_unit.downcase!
      unit_symbol = Volume::UNITS_SYMBOL[c_unit] || c_unit
      raise ArgumentError, 'Unpossible conversion type' unless Volume::UNITS.include?(unit_symbol)
      Volume.new(convert_to(unit_symbol), unit_symbol)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
convert_unit-0.1.0 lib/convert_unit/volume.rb