Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Router
- # initializing a router object that takes a controller
- # controller needs to come from outside, because it will store data (it already stores the repo!)
- def initialize(controller)
- @controller = controller
- @running = true
- end
- # the method that will run the software loop
- def run
- while @running == true do
- # calling private methods of our Router class
- user_choice = display_choices
- route_to(user_choice)
- end
- # if the loop ends, say goodbye
- puts "Bye bye"
- end
- private
- def route_to(user_choice)
- # route the user to the right action in the controller
- case user_choice
- when 1 then @controller.create_new_task
- when 2 then @controller.display_all_tasks
- when 3 then @controller.finish_a_task
- when 4 then @controller.delete_a_task
- else
- # if user presses any other key, set @running to false to stop the loop
- @running = false
- end
- end
- def display_choices
- # print all the choices for the user
- # ***TODO***: Do we want the welcome message display every time? Or should we move it somewhere else?
- puts "Welcome to the TODO MACHINE 300"
- puts "What is your command?"
- puts "Press 1 to create a new task"
- puts "Press 2 to show task list"
- puts "Press 3 to complete task"
- puts "Press 4 to delete a task"
- puts "Press any other key to exit"
- return gets.chomp.to_i
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement