Sha256: 69dd2a429ddedc7ce5aaab426fa439ca503e19ca9c2a597c0a33a7328bc9461e

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 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

      if VALID_TYPES.exclude?(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

3 entries across 3 versions & 1 rubygems

Version Path
freight_kit-0.1.11 lib/freight_kit/packaging.rb
freight_kit-0.1.10 lib/freight_kit/packaging.rb
freight_kit-0.1.7 lib/freight_kit/packaging.rb