Class: Kitchen::Pantry

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/kitchen/pantry.rb

Overview

A place to store labeled items during recipe work. Essentially, a slightly improved hash.

Instance Method Summary collapse

Instance Method Details

#each {|label, item| ... } ⇒ Object

Iterate over the pantry items

Yields:

  • Gives each label and item pair to the block

Yield Parameters:

  • label (Symbol)

    the item’s label

  • item (Object)

    the item



43
44
45
# File 'lib/kitchen/pantry.rb', line 43

def each(&block)
  @hash.each { |k, v| block.call(k, v) }
end

#get(label) ⇒ Object

Get an item from the pantry

Parameters:

  • label (String, Symbol)

    the item’s label

Returns:



23
24
25
# File 'lib/kitchen/pantry.rb', line 23

def get(label)
  @hash[label.to_sym]
end

#get!(label) ⇒ Object

Get an item from the pantry, raising if not present

Parameters:

  • label (String, Symbol)

    the item’s label

Returns:

Raises:



33
34
35
# File 'lib/kitchen/pantry.rb', line 33

def get!(label)
  get(label) || raise(RecipeError, "There is no pantry item labeled '#{label}'")
end

#sizeInteger

Returns the number of items in the pantry

Returns:



51
52
53
# File 'lib/kitchen/pantry.rb', line 51

def size
  @hash.keys.size
end

#store(item, label:) ⇒ Object

Adds an item to the pantry with the provided label

Parameters:

  • item (Object)

    something to store

  • label (String, Symbol)

    a label with which to retrieve this item later.



14
15
16
# File 'lib/kitchen/pantry.rb', line 14

def store(item, label:)
  @hash[label.to_sym] = item
end