Class: Comable::Inventory::Packer
- Inherits:
-
Object
- Object
- Comable::Inventory::Packer
- Defined in:
- app/models/comable/inventory/packer.rb
Instance Attribute Summary collapse
-
#stock_location ⇒ Object
Returns the value of attribute stock_location.
-
#units ⇒ Object
Returns the value of attribute units.
Instance Method Summary collapse
-
#initialize(stock_location, units) ⇒ Packer
constructor
A new instance of Packer.
- #package ⇒ Object
Constructor Details
#initialize(stock_location, units) ⇒ Packer
Returns a new instance of Packer.
7 8 9 10 |
# File 'app/models/comable/inventory/packer.rb', line 7 def initialize(stock_location, units) @stock_location = stock_location @units = units end |
Instance Attribute Details
#stock_location ⇒ Object
Returns the value of attribute stock_location.
4 5 6 |
# File 'app/models/comable/inventory/packer.rb', line 4 def stock_location @stock_location end |
#units ⇒ Object
Returns the value of attribute units.
5 6 7 |
# File 'app/models/comable/inventory/packer.rb', line 5 def units @units end |
Instance Method Details
#package ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/comable/inventory/packer.rb', line 12 def package package = Package.new(stock_location) units.group_by(&:variant).each do |variant, variant_units| stock = stock_location.find_stock_item(variant) next unless stock package.add variant_units.take(stock.quantity) if stock.stocked? end package end |