Class: Comable::Inventory::Packer

Inherits:
Object
  • Object
show all
Defined in:
app/models/comable/inventory/packer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_locationObject

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

#unitsObject

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

#packageObject



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