Class: FreightKit::Packaging

Inherits:
Object
  • Object
show all
Defined in:
lib/freight_kit/packaging.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, options = {}) ⇒ Packaging

Packaging.new(:pallet)



27
28
29
30
31
32
33
34
35
36
# File 'lib/freight_kit/packaging.rb', line 27

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

Instance Attribute Details

#typeObject

Returns the value of attribute type.



24
25
26
# File 'lib/freight_kit/packaging.rb', line 24

def type
  @type
end

Instance Method Details

#box?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/freight_kit/packaging.rb', line 38

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

#box_or_pallet_typeObject



46
47
48
49
50
# File 'lib/freight_kit/packaging.rb', line 46

def box_or_pallet_type
  return :pallet if pallet?

  box? ? :box : nil
end

#pallet?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/freight_kit/packaging.rb', line 42

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