Class: Kitchen::Clipboard
- 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
-
#add(item) ⇒ Object
Add an element to the clipboard.
-
#clear ⇒ Object
Clears the clipboard.
-
#each { ... } ⇒ Clipboard
Iterates over each item on the clipboard.
-
#initialize ⇒ Clipboard
constructor
Creates a new
Clipboard
. -
#items ⇒ Array<ElementBase>
The underlying array.
-
#paste ⇒ String
Returns a concatenation of the pasting of each item on the clipboard.
-
#sort_by! { ... } ⇒ Clipboard
Sorts the clipboard using the provided block.
Constructor Details
#initialize ⇒ Clipboard
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
27 28 29 30 |
# File 'lib/kitchen/clipboard.rb', line 27 def add(item) @items.push(item) self end |
#clear ⇒ Object
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
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 |
#items ⇒ Array<ElementBase>
The underlying array
13 14 15 |
# File 'lib/kitchen/clipboard.rb', line 13 def items @items.clone end |
#paste ⇒ String
Returns a concatenation of the pasting of each item on the clipboard
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
63 64 65 66 |
# File 'lib/kitchen/clipboard.rb', line 63 def sort_by!(&block) @items.sort_by!(&block) self end |