-
Notifications
You must be signed in to change notification settings - Fork 35
/
router.rb
35 lines (32 loc) · 828 Bytes
/
router.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Router
def initialize(meals_controller, customers_controller)
@meals_controller = meals_controller
@customers_controller = customers_controller
end
def run
loop do
# 1. Print the menu
print_menu
# 2. Ask the user what he/she wants to do next?
puts "What do you want to do next?"
print "> "
action = gets.chomp.to_i
# 3. Call the right controller method
case action
when 1 then @meals_controller.add
when 2 then @meals_controller.list
when 3 then @customers_controller.add
when 4 then @customers_controller.list
else
puts "Wrong action"
end
end
end
private
def print_menu
puts "1. Add a meal"
puts "2. List available meals"
puts "3. Add a customer"
puts "4. List customers"
end
end