Class: Workarea::Inventory::Collection
- Inherits:
-
Object
- Object
- Workarea::Inventory::Collection
- Includes:
- Enumerable
- Defined in:
- app/models/workarea/inventory/collection.rb
Overview
Instance Attribute Summary collapse
-
#skus ⇒ Object
readonly
Returns the value of attribute skus.
Instance Method Summary collapse
-
#available_to_sell ⇒ Object
The total number available to sell.
-
#for_sku(sku) ⇒ Sku
Grab the specific Sku for a SKU.
-
#initialize(skus, records = nil) ⇒ Collection
constructor
A new instance of Collection.
- #policies ⇒ Object
- #records ⇒ Object
Constructor Details
#initialize(skus, records = nil) ⇒ Collection
Returns a new instance of Collection.
12 13 14 15 |
# File 'app/models/workarea/inventory/collection.rb', line 12 def initialize(skus, records = nil) @skus = skus @records = records end |
Instance Attribute Details
#skus ⇒ Object (readonly)
Returns the value of attribute skus.
9 10 11 |
# File 'app/models/workarea/inventory/collection.rb', line 9 def skus @skus end |
Instance Method Details
#available_to_sell ⇒ Object
The total number available to sell
return [Integer]
21 22 23 |
# File 'app/models/workarea/inventory/collection.rb', line 21 def available_to_sell records.map(&:available_to_sell).sum end |
#for_sku(sku) ⇒ Sku
31 32 33 |
# File 'app/models/workarea/inventory/collection.rb', line 31 def for_sku(sku) records.detect { |r| r.id == sku } end |
#policies ⇒ Object
35 36 37 |
# File 'app/models/workarea/inventory/collection.rb', line 35 def policies records.map(&:policy) end |
#records ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'app/models/workarea/inventory/collection.rb', line 39 def records @records ||= begin existing = Sku.in(id: skus).to_a missing_skus = skus - existing.map(&:id) existing + missing_skus.map { |sku| Sku.new(id: sku ) } end end |