-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.rb
More file actions
70 lines (61 loc) · 1.61 KB
/
handler.rb
File metadata and controls
70 lines (61 loc) · 1.61 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
require_relative './store'
require_relative 'storage'
class Handler
include JsonStorage
include Storage
def add_music_album
puts 'Album name: '
name = gets.chomp
puts 'Genre: '
genre_name = gets.chomp
@genres.push(Genre.new(genre_name))
store_genre_data
puts 'Date of publish [Enter date in format (yyyy-mm-dd)]'
publish_date = gets.chomp
puts 'Is it available on Spotify? Y/N'
on_spotify = gets.chomp.downcase
case on_spotify
when 'y'
@music_albums.push(MusicAlbum.new(name, publish_date, true))
when 'n'
@music_albums.push(MusicAlbum.new(name, publish_date, false))
end
puts 'Music album created'
store_music_data
end
def albums
music_data = get_data('./store/music_albums.json')
puts 'No music found' if music_data.empty?
music_data.each do |music_album|
puts "Album_name: #{music_album['music_name']} | On_spotify: #{music_album['music_on_spotify']}"
end
end
def genres
data = get_data('./store/genres.json')
puts 'No genre found' if data.empty?
data.each do |genre|
puts "Genre name: #{genre['genre_name']}"
end
end
def store_music_data
array = []
@music_albums.each do |music|
array << {
music_id: music.id,
music_name: music.name,
music_on_spotify: music.on_spotify
}
end
update_data(array, './store/music_albums.json')
end
def store_genre_data
array = []
@genres.each do |genre|
array << {
genre_id: genre.id,
genre_name: genre.name
}
end
update_data(array, './store/genres.json')
end
end