Class: Puppet::Cleaner::Line
- Inherits:
-
Object
- Object
- Puppet::Cleaner::Line
- Defined in:
- lib/puppet-cleaner/line.rb
Instance Attribute Summary collapse
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
- #advance!(n = 1) ⇒ Object
- #append(pos, parts) ⇒ Object
- #back!(n = 1) ⇒ Object
- #current ⇒ Object
- #empty? ⇒ Boolean
- #hire(workers) ⇒ Object
-
#initialize(parts) ⇒ Line
constructor
A new instance of Line.
- #insert(pos, parts) ⇒ Object
- #inspect ⇒ Object
- #last? ⇒ Boolean
- #lookup(name, ignore = []) ⇒ Object
- #next(n = 1) ⇒ Object
- #parts ⇒ Object
- #prev(n = 1) ⇒ Object
- #remove(pos) ⇒ Object
- #reset! ⇒ Object
- #show ⇒ Object
- #size ⇒ Object
- #start ⇒ Object
- #transform! ⇒ Object
Constructor Details
Instance Attribute Details
#position ⇒ Object (readonly)
Returns the value of attribute position.
5 6 7 |
# File 'lib/puppet-cleaner/line.rb', line 5 def position @position end |
Instance Method Details
#advance!(n = 1) ⇒ Object
56 57 58 |
# File 'lib/puppet-cleaner/line.rb', line 56 def advance!(n = 1) @position += n end |
#append(pos, parts) ⇒ Object
104 105 106 |
# File 'lib/puppet-cleaner/line.rb', line 104 def append(pos, parts) @parts.insert(pos + 1, *parts) end |
#back!(n = 1) ⇒ Object
60 61 62 |
# File 'lib/puppet-cleaner/line.rb', line 60 def back!(n = 1) @position -= n end |
#current ⇒ Object
72 73 74 |
# File 'lib/puppet-cleaner/line.rb', line 72 def current @parts[@position] end |
#empty? ⇒ Boolean
64 65 66 |
# File 'lib/puppet-cleaner/line.rb', line 64 def empty? @position >= 0 && @position >= size end |
#hire(workers) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/puppet-cleaner/line.rb', line 13 def hire(workers) @workers.clear workers.each do |worker| worker.part_names.each {|part_name| @workers[part_name] << worker } end end |
#insert(pos, parts) ⇒ Object
100 101 102 |
# File 'lib/puppet-cleaner/line.rb', line 100 def insert(pos, parts) @parts.insert(pos, *parts) end |
#inspect ⇒ Object
32 33 34 |
# File 'lib/puppet-cleaner/line.rb', line 32 def inspect @parts.inject("") {|m, part| m += "#{part.name.inspect}\t#{part.value.inspect}\n"} end |
#last? ⇒ Boolean
84 85 86 |
# File 'lib/puppet-cleaner/line.rb', line 84 def last? @position == (size - 1) end |
#lookup(name, ignore = []) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/puppet-cleaner/line.rb', line 88 def lookup(name, ignore = []) position = @position while position < size && !(ignore + [name]).include?(@parts[position].name) position += 1 end position == size || @parts[position].name != name ? nil : position end |
#next(n = 1) ⇒ Object
76 77 78 |
# File 'lib/puppet-cleaner/line.rb', line 76 def next(n = 1) (@position + n) >= size ? NoPart : @parts[@position + n] end |
#parts ⇒ Object
68 69 70 |
# File 'lib/puppet-cleaner/line.rb', line 68 def parts @parts end |
#prev(n = 1) ⇒ Object
80 81 82 |
# File 'lib/puppet-cleaner/line.rb', line 80 def prev(n = 1) (@position - n) < 0 ? NoPart : @parts[@position - n] end |
#remove(pos) ⇒ Object
96 97 98 |
# File 'lib/puppet-cleaner/line.rb', line 96 def remove(pos) @parts.delete_at(pos) end |
#reset! ⇒ Object
52 53 54 |
# File 'lib/puppet-cleaner/line.rb', line 52 def reset! @position = 0 end |
#show ⇒ Object
36 37 38 |
# File 'lib/puppet-cleaner/line.rb', line 36 def show start {|part| context = {:before => prev, :after => self.next}; part.show(context) } end |
#size ⇒ Object
48 49 50 |
# File 'lib/puppet-cleaner/line.rb', line 48 def size @parts.size end |
#start ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/puppet-cleaner/line.rb', line 40 def start reset! while !empty? yield current advance! end end |
#transform! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/puppet-cleaner/line.rb', line 20 def transform! start do |part| @workers[part.name].each do |worker| worker.operate(self) if part.object_id != current.object_id back! break end end end end |