Class: Kitchen::Clipboard

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

Overview

A place to store lists of things during recipe work. Essentially a slightly fancy array.

Instance Method Summary collapse

Constructor Details

#initializeClipboard

Creates a new Clipboard



19
20
21
# File 'lib/kitchen/clipboard.rb', line 19

def initialize
  clear
end

Instance Method Details

#add(item) ⇒ Object

Add an element to the clipboard

Parameters:



27
28
29
30
# File 'lib/kitchen/clipboard.rb', line 27

def add(item)
  @items.push(item)
  self
end

#clearObject

Clears the clipboard



34
35
36
37
# File 'lib/kitchen/clipboard.rb', line 34

def clear
  @items = []
  self
end

#each { ... } ⇒ Clipboard

Iterates over each item on the clipboard

Yields:

  • each item

Returns:



50
51
52
53
54
55
56
57
# File 'lib/kitchen/clipboard.rb', line 50

def each(&block)
  if block_given?
    @items.each do |item|
      block.call(item)
    end
  end
  self
end

#itemsArray<ElementBase>

The underlying array

Returns:



13
14
15
# File 'lib/kitchen/clipboard.rb', line 13

def items
  @items.clone
end

#pasteString

Returns a concatenation of the pasting of each item on the clipboard

Returns:



42
43
44
# File 'lib/kitchen/clipboard.rb', line 42

def paste
  @items.map(&:paste).join('')
end

#sort_by! { ... } ⇒ Clipboard

Sorts the clipboard using the provided block

Yields:

  • each item

Returns:



63
64
65
66
# File 'lib/kitchen/clipboard.rb', line 63

def sort_by!(&block)
  @items.sort_by!(&block)
  self
end