Class: Physical::Pallet

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

Overview

Represents a physical pallet which holds boxes.

Constant Summary collapse

DEFAULT_LENGTH =

The default dimensions of this pallet when unspecified

BigDecimal::INFINITY
DEFAULT_MAX_WEIGHT =

The default maximum weight of this pallet when unspecified

BigDecimal::INFINITY

Instance Attribute Summary collapse

Attributes inherited from Cuboid

#id, #properties, #weight

Instance Method Summary collapse

Methods inherited from Cuboid

#==, #density

Constructor Details

#initialize(**kwargs) ⇒ Pallet

Returns a new instance of Pallet.

Parameters:

  • kwargs (Hash)

    ID, dimensions, weight, and properties

Options Hash (**kwargs):

  • :id (String)

    a unique identifier for this pallet

  • :dimensions (Array<Measured::Length>)

    the length, width, and height of this pallet

  • :weight (Measured::Weight)

    the weight of the pallet itself (excluding what's on top)

  • :max_weight (Measured::Weight)

    the maximum weight this pallet can handle

  • :properties (Hash)

    additional custom properties for this pallet



24
25
26
27
28
# File 'lib/physical/pallet.rb', line 24

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

Instance Attribute Details

#max_weightMeasured::Weight (readonly)

The maximum weight this pallet can handle

Returns:

  • (Measured::Weight)


16
17
18
# File 'lib/physical/pallet.rb', line 16

def max_weight
  @max_weight
end

Instance Method Details

#dimensionsArray<Measured::Length> Also known as: inner_dimensions

Returns the dimensions of this pallet.

Returns:

  • (Array<Measured::Length>)

    the dimensions of this pallet



36
# File 'lib/physical/pallet.rb', line 36

alias_method :inner_dimensions, :dimensions

#heightMeasured::Length Also known as: inner_height

Returns the height of this pallet.

Returns:

  • (Measured::Length)

    the height of this pallet



48
# File 'lib/physical/pallet.rb', line 48

alias_method :inner_height, :height

#lengthMeasured::Length Also known as: inner_length

Returns the length of this pallet.

Returns:

  • (Measured::Length)

    the length of this pallet



40
# File 'lib/physical/pallet.rb', line 40

alias_method :inner_length, :length

#package_fits?(package) ⇒ Boolean

Returns true if the given package can fit on the pallet. Checks package dimensions and weight against pallet dimensions and max weight.

Parameters:

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
# File 'lib/physical/pallet.rb', line 54

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

#volumeMeasured::Volume Also known as: inner_volume

Returns the volume of this pallet.

Returns:

  • (Measured::Volume)

    the volume of this pallet



32
# File 'lib/physical/pallet.rb', line 32

alias_method :inner_volume, :volume

#widthMeasured::Length Also known as: inner_width

Returns the width of this pallet.

Returns:

  • (Measured::Length)

    the width of this pallet



44
# File 'lib/physical/pallet.rb', line 44

alias_method :inner_width, :width