-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
55 lines (47 loc) · 1.13 KB
/
main.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
require './app'
class LibraryApp
def initialize
@app = App.new
run
end
def show_menu
puts 'Please choose an option by entering a number:'
puts '1 - List all books'
puts '2 - List all people'
puts '3 - Create a person'
puts '4 - Create a book'
puts '5 - Create a rental'
puts '6 - List all rentals for a given person id'
puts '7 - Exit'
end
def user_option
gets.chomp
end
def choose_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 },
'7' => lambda {
puts 'Exiting...'
@running = false
},
'default' => -> { puts 'Invalid value!' }
}
action = actions[option] || actions['default']
action.call
end
def run
puts 'Welcome to the school library App!'
@running = true
while @running
show_menu
selected_option = user_option
choose_option(selected_option)
end
end
end
LibraryApp.new