generated from manq2010/ruby-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
73 lines (66 loc) · 1.49 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
require_relative './user_interface/book_ui'
require_relative './user_interface/game_ui'
require_relative './user_interface/author_ui'
require_relative './user_interface/music_album_ui'
class Main
attr_accessor :book, :label, :game, :music_album, :genre
def initialize
@book = BookUserInterface.new
@game = GameUserInterface.new
@authors = AuthorUserInterface.new
@music_album = MusicAlbumUserInterface.new
end
def options
puts [
'1- List all books',
'2- List all music albums',
'3- List of games',
'4- List all genres',
'5- List all labels (e.g. \'Gift\', \'New\')',
'6- List all authors (e.g. \'Stephen King\')',
'7- Add a book',
'8- Add a music album',
'9- Add a game',
'10- Exit'
]
end
def processed_input(input)
case input
when 1
@book.list_all_books
when 2
@music_album.list_all_music_albums
when 3
@game.list_all_games
when 4
@music_album.list_all_genres
when 5
@book.list_all_labels
end
end
def processed_input2(input)
case input
when 6
@authors.list_authors
puts ''
when 7
@book.add_a_book
when 8
@music_album.add_a_music_album
when 9
@game.add_game
end
end
end
def main
main = Main.new
input = nil
until input == 10
main.options
input = gets.to_i
puts 'Invalid choice' if input < 1 || input > 10
main.processed_input(input)
main.processed_input2(input)
end
end
main