Class: Logistics::Core::UnitService

Inherits:
BaseService show all
Defined in:
app/services/logistics/core/unit_service.rb

Instance Method Summary collapse

Methods inherited from BaseService

#to_json

Instance Method Details

#convert_unit(amount, abbreviation, to_base = true) ⇒ Object



4
5
6
7
8
9
10
11
# File 'app/services/logistics/core/unit_service.rb', line 4

def convert_unit(amount, abbreviation, to_base = true)
  rate = Unit.find_by(abbreviation: abbreviation).rate_to_base
  if rate
    to_base ? amount / rate : amount * rate
  else
    raise 'You have no unit conversion rate'
  end
end