Class: Step
- Inherits:
-
Object
- Object
- Step
- Defined in:
- lib/tuvi/step.rb
Instance Attribute Summary collapse
-
#code_blocks ⇒ Object
Returns the value of attribute code_blocks.
-
#exit_program ⇒ Object
Returns the value of attribute exit_program.
-
#id ⇒ Object
Returns the value of attribute id.
-
#response_paths ⇒ Object
Returns the value of attribute response_paths.
Instance Method Summary collapse
- #code(&block) ⇒ Object
- #formatted_responses ⇒ Object
- #get_say ⇒ Object
-
#initialize(id, &block) ⇒ Step
constructor
A new instance of Step.
- #response(response_path) ⇒ Object
- #say(text) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(id, &block) ⇒ Step
Returns a new instance of Step.
5 6 7 8 9 10 |
# File 'lib/tuvi/step.rb', line 5 def initialize(id, &block) @id = id @response_paths = {} @code_blocks = [] instance_eval(&block) if block_given? end |
Instance Attribute Details
#code_blocks ⇒ Object
Returns the value of attribute code_blocks.
3 4 5 |
# File 'lib/tuvi/step.rb', line 3 def code_blocks @code_blocks end |
#exit_program ⇒ Object
Returns the value of attribute exit_program.
3 4 5 |
# File 'lib/tuvi/step.rb', line 3 def exit_program @exit_program end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/tuvi/step.rb', line 3 def id @id end |
#response_paths ⇒ Object
Returns the value of attribute response_paths.
3 4 5 |
# File 'lib/tuvi/step.rb', line 3 def response_paths @response_paths end |
Instance Method Details
#code(&block) ⇒ Object
34 35 36 |
# File 'lib/tuvi/step.rb', line 34 def code(&block) code_blocks << block end |
#formatted_responses ⇒ Object
30 31 32 |
# File 'lib/tuvi/step.rb', line 30 def formatted_responses "Choose a command: [#{@response_paths.keys.join(", ")}]" end |
#get_say ⇒ Object
16 17 18 |
# File 'lib/tuvi/step.rb', line 16 def get_say @say end |
#response(response_path) ⇒ Object
20 21 22 23 24 |
# File 'lib/tuvi/step.rb', line 20 def response(response_path) response = response_path.first[0].downcase next_step = response_path.first[1] @response_paths[response] = next_step end |
#say(text) ⇒ Object
12 13 14 |
# File 'lib/tuvi/step.rb', line 12 def say(text) @say = text end |
#stop ⇒ Object
26 27 28 |
# File 'lib/tuvi/step.rb', line 26 def stop @exit_program = true end |