class ApplicationRunner
Public Class Methods
new(steps)
click to toggle source
# File lib/tuvi/application_runner.rb, line 3 def initialize(steps) @steps = steps end
Public Instance Methods
determine_next_step(current_step, input)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/tuvi/application_runner.rb, line 38 def exit_program puts "Bye!" exit end
run()
click to toggle source
# 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