Class: Leash::Procedure
- Inherits:
-
Object
- Object
- Leash::Procedure
- Defined in:
- lib/leash/procedure.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(title, options = {}, &block) ⇒ Procedure
constructor
A new instance of Procedure.
- #length ⇒ Object
- #render ⇒ Object
- #run ⇒ Object
- #step(description, action = nil, &block) ⇒ Object
Constructor Details
#initialize(title, options = {}, &block) ⇒ Procedure
Returns a new instance of Procedure.
7 8 9 10 11 12 13 |
# File 'lib/leash/procedure.rb', line 7 def initialize(title, = {}, &block) @title = title @options = @steps = [] instance_eval(&block) if block end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/leash/procedure.rb', line 5 def @options end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
5 6 7 |
# File 'lib/leash/procedure.rb', line 5 def steps @steps end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/leash/procedure.rb', line 5 def title @title end |
Instance Method Details
#length ⇒ Object
43 44 45 |
# File 'lib/leash/procedure.rb', line 43 def length steps.length end |
#render ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/leash/procedure.rb', line 33 def render text = +"#{title}\n" steps.each_with_index do |step, index| text << "(#{index.next}/#{length}): #{step.description}\n" end text end |
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/leash/procedure.rb', line 22 def run puts "Running: #{title}" steps.each_with_index do |step, index| puts("(#{index.next}/#{length}): #{step.description}") puts "> Press Enter to continue ..." $stdin.gets step.run end end |