Module: FoundationKit::InventoryMixin

Included in:
Inventory
Defined in:
lib/foundation_kit/inventory.rb

Overview

Inventory mixin methods

Author:

  • jcrum

Instance Method Summary collapse

Instance Method Details

#add(name:, item:) ⇒ Object

Adds an item to inventory

Parameters:

  • name: (String, Symbol)

    Name of the item being added

  • item: (Object)

    The item being added to inventory



14
15
16
# File 'lib/foundation_kit/inventory.rb', line 14

def add(name:, item:)
  stock[name.to_sym] = item
end

#countInteger

Returns the inventory count

Returns:

  • (Integer)


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

Returns:

  • (type)
    description


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

Parameters:

  • name: (String, Symbol)

    Item name to be removed



45
46
47
# File 'lib/foundation_kit/inventory.rb', line 45

def remove(name:)
  stock.delete(name.to_sym)
end

#stockHash

Returns the current items in Inventory

Returns:

  • (Hash)


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

Returns:

  • (Boolean)


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

Parameters:

  • name: (String, Symbol)

Returns:

  • (Object)

    Item referenced by the supplied name



62
63
64
# File 'lib/foundation_kit/inventory.rb', line 62

def use(name:)
  stock[name.to_sym]
end