Class: Shipping::PackingCalculator::Bin

Inherits:
Struct
  • Object
show all
Defined in:
app/services/shipping/packing_calculator.rb

Overview

A Bin accumulates units until weight or spatial capacity is exhausted.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#total_weightObject

Returns the value of attribute total_weight

Returns:

  • (Object)

    the current value of total_weight



79
80
81
# File 'app/services/shipping/packing_calculator.rb', line 79

def total_weight
  @total_weight
end

#unitsObject

Returns the value of attribute units

Returns:

  • (Object)

    the current value of units



79
80
81
# File 'app/services/shipping/packing_calculator.rb', line 79

def units
  @units
end

Instance Method Details

#add(unit) ⇒ Object



80
81
82
83
# File 'app/services/shipping/packing_calculator.rb', line 80

def add(unit)
  units << unit
  self.total_weight += unit.weight
end

#all_dimensionsObject



85
86
87
# File 'app/services/shipping/packing_calculator.rb', line 85

def all_dimensions
  units.map(&:dimensions)
end

#contents_by_itemObject

Groups units by item_id for Shipping::Container#add_content calls.



94
95
96
# File 'app/services/shipping/packing_calculator.rb', line 94

def contents_by_item
  units.group_by(&:item_id).transform_values(&:count)
end

#weight_allows?(unit) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
# File 'app/services/shipping/packing_calculator.rb', line 89

def weight_allows?(unit)
  total_weight + unit.weight <= PER_BOX_WEIGHT_LIMIT
end