Module: FoundationKit::InventoryMixin
- Included in:
- Inventory
- Defined in:
- lib/foundation_kit/inventory.rb
Overview
Inventory mixin methods
Instance Method Summary collapse
-
#add(name:, item:) ⇒ Object
Adds an item to inventory.
-
#count ⇒ Integer
Returns the inventory count.
-
#out_of_stock? ⇒ type
Returns whether or not the Inventory is empty.
-
#remove(name:) ⇒ Object
Removes an item from Inventory.
-
#stock ⇒ Hash
Returns the current items in Inventory.
-
#stock? ⇒ Boolean
Returns whether or not the inventory has items.
-
#use(name:) ⇒ Object
Allows an item in inventory to be used.
Instance Method Details
#add(name:, item:) ⇒ Object
Adds an item to inventory
14 15 16 |
# File 'lib/foundation_kit/inventory.rb', line 14 def add(name:, item:) stock[name.to_sym] = item end |
#count ⇒ Integer
Returns the inventory count
22 23 24 |
# File 'lib/foundation_kit/inventory.rb', line 22 def count stock.count end |
#out_of_stock? ⇒ type
Returns whether or not the Inventory is empty
38 39 40 |
# File 'lib/foundation_kit/inventory.rb', line 38 def out_of_stock? stock.count.zero? end |
#remove(name:) ⇒ Object
Removes an item from Inventory
45 46 47 |
# File 'lib/foundation_kit/inventory.rb', line 45 def remove(name:) stock.delete(name.to_sym) end |
#stock ⇒ Hash
Returns the current items in Inventory
53 54 55 |
# File 'lib/foundation_kit/inventory.rb', line 53 def stock @stock ||= {} end |
#stock? ⇒ Boolean
Returns whether or not the inventory has items
30 31 32 |
# File 'lib/foundation_kit/inventory.rb', line 30 def stock? !stock.count.zero? end |
#use(name:) ⇒ Object
Allows an item in inventory to be used
62 63 64 |
# File 'lib/foundation_kit/inventory.rb', line 62 def use(name:) stock[name.to_sym] end |