Class: ApplicationRunner
- Inherits:
-
Object
- Object
- ApplicationRunner
- Defined in:
- lib/tuvi/application_runner.rb
Instance Method Summary collapse
- #determine_next_step(current_step, input) ⇒ Object
- #execute_step(step_id) ⇒ Object
- #exit_program ⇒ Object
-
#initialize(steps) ⇒ ApplicationRunner
constructor
A new instance of ApplicationRunner.
- #run ⇒ Object
Constructor Details
#initialize(steps) ⇒ ApplicationRunner
Returns a new instance of ApplicationRunner.
3 4 5 |
# File 'lib/tuvi/application_runner.rb', line 3 def initialize(steps) @steps = steps end |
Instance Method Details
#determine_next_step(current_step, input) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/tuvi/application_runner.rb', line 29 def determine_next_step(current_step, input) if current_step.response_paths[input] return current_step.response_paths[input] end puts "Sorry, I don't understand that response. Please try again:" current_step.id end |
#execute_step(step_id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tuvi/application_runner.rb', line 15 def execute_step(step_id) current_step = @steps[step_id] current_step.code_blocks.each do |block| block.call end puts puts current_step.get_say exit if current_step.exit_program puts current_step.formatted_responses input = gets.downcase.chomp exit_program if input == "exit" determine_next_step(current_step, input) end |
#exit_program ⇒ Object
38 39 40 41 |
# File 'lib/tuvi/application_runner.rb', line 38 def exit_program puts "Bye!" exit end |
#run ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/tuvi/application_runner.rb', line 7 def run puts "Welcome! Type 'exit' to quit at any time." current_step_id = "start" while true do current_step_id = execute_step(current_step_id) end end |