Class: Comable::Inventory::Package

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stock_location) ⇒ Package

Returns a new instance of Package.



9
10
11
12
# File 'app/models/comable/inventory/package.rb', line 9

def initialize(stock_location)
  @stock_location = stock_location
  @units = []
end

Instance Attribute Details

#stock_locationObject

Returns the value of attribute stock_location.



4
5
6
# File 'app/models/comable/inventory/package.rb', line 4

def stock_location
  @stock_location
end

#unitsObject

Returns the value of attribute units.



5
6
7
# File 'app/models/comable/inventory/package.rb', line 5

def units
  @units
end

Instance Method Details

#add(unit) ⇒ Object



29
30
31
32
# File 'app/models/comable/inventory/package.rb', line 29

def add(unit)
  unit = [unit] unless unit.is_a? Array
  units.concat(unit)
end

#find(unit) ⇒ Object



25
26
27
# File 'app/models/comable/inventory/package.rb', line 25

def find(unit)
  units.detect { |u| u == unit }
end

#initialize_copy(package) ⇒ Object



14
15
16
17
# File 'app/models/comable/inventory/package.rb', line 14

def initialize_copy(package)
  super
  self.units = package.units.clone
end

#remove(unit) ⇒ Object



34
35
36
# File 'app/models/comable/inventory/package.rb', line 34

def remove(unit)
  units.delete(unit)
end

#to_shipmentObject



19
20
21
22
23
# File 'app/models/comable/inventory/package.rb', line 19

def to_shipment
  shipment = Comable::Shipment.new(stock_location: stock_location)
  shipment.shipment_items = build_shipment_items(shipment)
  shipment
end