generated from Saancha/ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstore.rb
31 lines (25 loc) · 856 Bytes
/
store.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
require 'json'
class Store
def store_books(obj)
File.write('./Data/books_data.json', obj)
end
def store_music_albums(obj)
File.write('./Data/music_albums_data.json', obj)
end
def load_books
books_file = File.open('./Data/books_data.json')
file_data = books_file.read
return [] if file_data == ''
JSON.parse(file_data, symbolize_names: true).map do |book|
Book.new(book[:title], book[:publish_date], book[:publisher], book[:cover_state], book[:author])
end
end
def load_music_albums
music_albums_file = File.open('./Data/music_albums_data.json')
file_data = music_albums_file.read
return [] if file_data == ''
JSON.parse(file_data, symbolize_names: true).map do |music_album|
MusicAlbum.new(music_album[:title], music_album[:genre], music_album[:publish_date])
end
end
end