Sha256: c89733d195c6ef35d73e19bb58d22dc9136e35ede4e9f2e8c5ee9c6456a7125d

Contents?: true

Size: 366 Bytes

Versions: 9

Compression:

Stored size: 366 Bytes

Contents

module Logistics
  module Core
    class UnitService < BaseService
      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
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
logistics_core-21.11.2 app/services/logistics/core/unit_service.rb
logistics_core-21.11.1 app/services/logistics/core/unit_service.rb
logistics_core-21.08.1 app/services/logistics/core/unit_service.rb
logistics_core-21.03.1 app/services/logistics/core/unit_service.rb
logistics_core-20.10.3 app/services/logistics/core/unit_service.rb
logistics_core-20.10.2 app/services/logistics/core/unit_service.rb
logistics_core-20.10.1 app/services/logistics/core/unit_service.rb
logistics_core-20.9.1 app/services/logistics/core/unit_service.rb
logistics_core-20.8.1 app/services/logistics/core/unit_service.rb