Class: Physical::Pallet

Inherits:
Cuboid
  • Object
show all
Defined in:
lib/physical/pallet.rb

Constant Summary collapse

DEFAULT_LENGTH =
BigDecimal::INFINITY
DEFAULT_MAX_WEIGHT =
BigDecimal::INFINITY

Instance Attribute Summary collapse

Attributes inherited from Cuboid

#dimensions, #height, #id, #length, #properties, #weight, #width

Instance Method Summary collapse

Methods inherited from Cuboid

#==, #density, #volume

Constructor Details

#initialize(**args) ⇒ Pallet

Returns a new instance of Pallet.



12
13
14
15
16
# File 'lib/physical/pallet.rb', line 12

def initialize(**args)
  max_weight = args.delete(:max_weight) || Measured::Weight(DEFAULT_MAX_WEIGHT, :g)
  super(**args)
  @max_weight = Types::Weight[max_weight]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Physical::PropertyReaders

Instance Attribute Details

#max_weightObject (readonly)

Returns the value of attribute max_weight.



10
11
12
# File 'lib/physical/pallet.rb', line 10

def max_weight
  @max_weight
end

Instance Method Details

#package_fits?(package) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
# File 'lib/physical/pallet.rb', line 26

def package_fits?(package)
  return false if package.weight > max_weight

  pallet_dimensions = dimensions.sort
  package.dimensions.sort.each.with_index do |axis, index|
    return false if axis >= pallet_dimensions.sort[index]
  end
  true
end