forked from jcmunav63/catalog-my-things
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
121 lines (100 loc) · 2.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
require_relative 'item'
require_relative 'book'
require_relative 'label'
require_relative 'catalog'
class Main
def initialize
@catalog = Catalog.new
end
def run
puts 'Welcome to the Catalog of my Personal Things'
loop do
display_menu
option = gets_option
break if option == 13
handle_option(option)
end
puts 'Thank you for using this app!'
end
private
def display_menu
puts '1) List all books'
puts '2) List all music albums'
puts '3) List all movies (disabled)'
puts '4) List of games'
puts '5) List all genres'
puts '6) List all labels'
puts '7) List all authors'
puts '8) List all sources (disabled)'
puts '9) Add a book'
puts '10) Add a music album'
puts '11) Add a movie (disabled)'
puts '12) Add a game'
puts '13) Exit the app'
end
def gets_option
print 'Enter your option here: '
gets.chomp.to_i
end
def handle_option(option)
method_name = option_methods[option]
if method_name
send(method_name)
else
puts 'Invalid option'
end
end
def option_methods
{
1 => :list_all_books,
2 => :list_all_music_albums,
3 => :list_all_movies,
4 => :list_all_games,
5 => :list_all_genres,
6 => :list_all_labels,
7 => :list_all_authors,
8 => :list_all_sources,
9 => :add_a_book,
10 => :add_a_music_album,
11 => :add_a_movie,
12 => :add_a_game
}
end
def list_all_books
@catalog.list_all_books
end
def list_all_music_albums
@catalog.list_all_music_albums
end
def list_all_movies
@catalog.list_all_movies
end
def list_all_games
@catalog.list_all_games
end
def list_all_genres
@catalog.list_all_genres
end
def list_all_labels
@catalog.list_all_labels
end
def list_all_authors
@catalog.list_all_authors
end
def list_all_sources
@catalog.list_all_sources
end
def add_a_book
@catalog.add_a_book
end
def add_a_music_album
@catalog.add_a_music_album
end
def add_a_movie
@catalog.add_a_movie
end
def add_a_game
@catalog.add_a_game
end
end
Main.new.run