Class: Shipping::PackingCalculator::Bin
- Inherits:
-
Struct
- Object
- Struct
- Shipping::PackingCalculator::Bin
- Defined in:
- app/services/shipping/packing_calculator.rb
Overview
A Bin accumulates units until weight or spatial capacity is exhausted.
Instance Attribute Summary collapse
-
#total_weight ⇒ Object
Returns the value of attribute total_weight.
-
#units ⇒ Object
Returns the value of attribute units.
Instance Method Summary collapse
- #add(unit) ⇒ Object
- #all_dimensions ⇒ Object
-
#contents_by_item ⇒ Object
Groups units by item_id for Shipping::Container#add_content calls.
- #weight_allows?(unit) ⇒ Boolean
Instance Attribute Details
#total_weight ⇒ Object
Returns the value of attribute total_weight
79 80 81 |
# File 'app/services/shipping/packing_calculator.rb', line 79 def total_weight @total_weight end |
#units ⇒ Object
Returns the value of attribute 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_dimensions ⇒ Object
85 86 87 |
# File 'app/services/shipping/packing_calculator.rb', line 85 def all_dimensions units.map(&:dimensions) end |
#contents_by_item ⇒ Object
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
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 |