-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rb
More file actions
95 lines (80 loc) · 1.63 KB
/
Copy pathmain.rb
File metadata and controls
95 lines (80 loc) · 1.63 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require_relative 'app'
class MainMenu
attr_reader :app
def initialize(app)
@app = app
end
def user_options(choice)
menu_options = {
1 => method(:list_books),
2 => method(:list_music),
3 => method(:list_games),
4 => method(:list_genres),
5 => method(:list_labels),
6 => method(:list_authors),
7 => method(:create_book),
8 => method(:create_music),
9 => method(:create_games),
0 => method(:exit_app)
}
if menu_options.key?(choice)
menu_options[choice].call(app)
else
puts 'Invalid option, please try again!'
end
end
def display
puts 'Welcome to your library'
puts 'Please choose an option'
puts '1. List all books'
puts '2. List all music albums'
puts '3. List all games'
puts '4. List all genres'
puts '5. List all labels'
puts '6. List all authors'
puts '7. Create a book'
puts '8. Create a music album'
puts '9. Create a game'
puts '0. Exit'
end
def list_books(app)
app.list_books
end
def list_music(app)
app.albums
end
def list_games(app)
app.list_games
end
def list_genres(app)
app.genres
end
def list_labels(app)
app.list_labels
end
def list_authors(app)
app.list_authors
end
def create_book(app)
app.create_book
end
def create_music(app)
app.add_music_album
end
def create_games(app)
app.create_games
end
def exit_app(app)
app.exit_app
end
end
def main
app = App.new
main_menu = MainMenu.new(app)
loop do
main_menu.display
choice = gets.chomp.to_i
main_menu.user_options(choice)
end
end
main