-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.rb
183 lines (165 loc) · 4.53 KB
/
app.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
require_relative 'classes/author'
require_relative 'classes/book'
require_relative 'classes/game'
require_relative 'classes/genre'
require_relative 'classes/item'
require_relative 'classes/label'
require_relative 'classes/music_album'
require_relative './modules/book_logic'
require_relative './modules/genre_logic'
require_relative './modules/label_logic'
require_relative './modules/music_logic'
require_relative './modules/author_logic'
require_relative './modules/games_logic'
class App
include AuthorModule
include BookModule
include GenreModule
include MusicAlbumModule
include LabelModule
include GamesModule
def initialize
@books = load_book
@genres = load_genres
@labels = load_label
@music_albums = load_music_albums
@authors = load_authors
@games = load_games
end
def save_data
create_games
create_book
create_genre
create_music_album
create_author
create_label
end
def run
puts "Welcome to my Catalog App!\n"
puts 'Please choose an option by entering a number:'
puts '1 - List all books'
puts '2 - List all music albums'
puts '3 - List of games'
puts '4 - List all genres'
puts '5 - List all labels'
puts '6 - List all authors'
puts '7 - Add a book'
puts '8 - Add a music album'
puts '9 - Add a game'
puts '10 - Exit'
option = gets.chomp.to_i
input(option)
run
end
def input(option)
case option
when 1
list_books
when 2
list_music_albums
when 3
list_all_games
when 4
list_genres
when 5
list_all_labels
when 6
list_all_authors
when 7
add_book
when 8
add_music_album
when 9
add_game
when 10
save_data
puts 'Thank you'
exit
else
puts 'invalid option'
end
end
def add_book
puts 'Please enter the title of the book:'
title = gets.chomp
puts 'Please enter the publish date of the book'
publish_date = gets.chomp
puts 'Enter the author\'s name'
author = gets.chomp
puts 'Please enter the Publisher of the book'
publisher = gets.chomp
puts 'Please enter the cover state of the book(eg. good, bad)'
cover_state = gets.chomp
puts 'book created'
book = Book.new(title, author, publisher, cover_state, publish_date)
@books.push(book)
@authors.push(Author.new(author))
end
def add_music_album
puts 'Add album name:'
name = gets.chomp
puts 'Publish_date'
publish_date = gets.chomp
puts 'On Spotify true or false'
on_spotify = gets.chomp == 'true'
puts 'What genre is the above music'
genre = gets.chomp
@genres.push(Genre.new(genre)) if @genres.none? { |g| g.name == genre }
@music_albums.push(MusicAlbum.new(name, publish_date, on_spotify))
puts 'Music album added'
end
def list_all_labels
puts 'no labels yet!' if @labels.empty?
@labels.each do |label|
puts "Title: #{label.title}, color: #{label.color}"
end
end
def list_books
puts 'There are no books yet!' if @books.empty?
@books.each do |book|
puts "Title: #{book.title}, Publisher: #{book.publisher}, Publish Date: #{book.publish_date},
Cover state: #{book.cover_state}"
end
end
def list_genres
puts 'There are no genres yet!' if @genres.empty?
@genres.each do |genre|
puts "Name: #{genre.name}"
end
end
def add_game
puts 'Please write multiplayer: '
multiplayer = gets.chomp
puts 'Please write date of publish [Enter date (yyyy-mm-dd)]'
publish_date = gets.chomp
puts 'Please write last played date [Enter date (yyyy-mm-dd)]'
last_played_date = gets.chomp
puts 'Please Input label\'s title'
title = gets.chomp
puts 'Please Inpute= label\'s color'
color = gets.chomp
@labels.push(Label.new(title, color))
@games.push(Game.new(multiplayer, publish_date, last_played_date))
puts 'Game is created'
end
def list_all_games
puts 'Games:'
@games.each do |games|
puts "Multiplayer: #{games.multiplayer}, Publish Date: #{games.publish_date},
Last played date: #{games.last_played_date}"
end
end
def list_all_authors
puts 'There are no authors yet!' if @authors.empty?
@authors.each do |author|
puts "Author's name is: #{author.full_name}"
end
end
def list_music_albums
puts 'There are no music albums yet!' if @music_albums.empty?
@music_albums.each do |music_album|
puts "Title: #{music_album.name}, Publish Date: #{music_album.publish_date},
On Spotify: #{music_album.on_spotify}"
end
end
end