-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.rb
76 lines (67 loc) · 1.67 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class Router
def initialize(meals_controller, customers_controller, sessions_controller, orders_controller)
@meals_controller = meals_controller
@customers_controller = customers_controller
@sessions_controller = sessions_controller
@orders_controller = orders_controller
@running = true
end
def run
while @running
@employee = @sessions_controller.login
while @employee
if @employee.manager?
print_manager_menu
action = get_user_action
do_manager_action(action)
else
print_delivery_guy_menu
action = get_user_action
do_delivery_guy_action(action)
end
end
end
end
private
def get_user_action
puts 'What do you want to do next?'
print '> '
return gets.chomp.to_i
end
def print_manager_menu
puts '1. Add a meal'
puts '2. List available meals'
puts '3. Add a customer'
puts '4. List customers'
puts '5. Logout'
puts '6. Exit'
end
def do_manager_action(action)
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
when 5 then @employee = nil
when 6
@employee = nil
@running = false
else
puts 'Wrong action'
end
end
def print_delivery_guy_menu
puts '1. List orders'
puts '2. Mark as delivered'
puts '3. Logout'
puts '4. Exit'
end
def do_delivery_guy_action(action)
case action
when 1 then puts @orders_controller.list(@employee)
when 2 then puts 'TODO: Mark as delivered'
else
puts 'Wrong action'
end
end
end