generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
menu.rb
46 lines (40 loc) · 1000 Bytes
/
menu.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
require './app'
class Menu
def initialize(app)
@app = app
end
def display
puts 'Welcome to School Library App!'
loop do
display_menu
option = gets.chomp.to_i
handle_option(option)
break if option == 7
end
end
private
def display_menu
puts '1. List Books'
puts '2. List People'
puts '3. Create Person'
puts '4. Create Book'
puts '5. Create Rental'
puts '6. List Rentals for a Person'
puts '7. Exit'
print 'Please select an option: '
end
def handle_option(option)
option_actions = {
1 => -> { @app.list_books },
2 => -> { @app.list_people },
3 => -> { @app.create_person },
4 => -> { @app.create_book },
5 => -> { @app.create_rental },
6 => -> { @app.list_rentals_for_person },
7 => -> { @app.exit_app },
default: -> { puts 'Enter a number between 1 and 7.' }
}
action = option_actions[option] || option_actions[:default]
action.call
end
end