Sha256: 32cdeaba5e54b10886ffee461913e1362618fb16cf55c12432b3e8420f6694a5

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module FreightKit
  class Packaging
    VALID_TYPES = %i[
                    box
                    bundle
                    container
                    crate
                    cylinder
                    drum
                    luggage
                    pail
                    pallet
                    piece
                    roll
                    tote
                    truckload
                    tote
                  ].freeze

    PALLET_TYPES = %i[crate drum pallet tote].freeze

    attr_accessor :type

    # Packaging.new(:pallet)
    def initialize(type, options = {})
      options.symbolize_keys!
      @options = options

      unless VALID_TYPES.include?(type)
        raise ArgumentError, "Package#new: `type` should be one of #{VALID_TYPES.join(", ")}"
      end

      @type = type
    end

    def box?
      @box ||= BOX_TYPES.include?(@type)
    end

    def pallet?
      @pallet ||= PALLET_TYPES.include?(@type)
    end

    def box_or_pallet_type
      return :pallet if pallet?

      box? ? :box : nil
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
freight_kit-0.1.4 lib/freight_kit/packaging.rb
freight_kit-0.1.3 lib/freight_kit/packaging.rb
freight_kit-0.1.2 lib/freight_kit/packaging.rb
freight_kit-0.1.1 lib/freight_kit/packaging.rb
freight_kit-0.1.0 lib/freight_kit/packaging.rb