Class: Pandoru::Models::BookmarkList
Instance Attribute Summary
Attributes inherited from Base
#data
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Collection
#<<, #[], #each, #empty?, #first, #initialize, #last, #length, #to_a
Methods inherited from Base
date_field, field, fields, from_json_list, #initialize, #inspect, #populate_from_json, #to_h
Class Method Details
.from_json(api_client, data) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/pandoru/models/bookmark.rb', line 36
def self.from_json(api_client, data)
instance = new(data, api_client)
if data['songs']
Bookmark.from_json_list(api_client, data['songs']).each do |bookmark|
instance << bookmark
end
end
if data['artists']
data['artists'].each do |artist_data|
artist_data['songName'] = nil unless artist_data.key?('songName')
bookmark = Bookmark.from_json(api_client, artist_data)
instance << bookmark
end
end
instance
end
|
Instance Method Details
#artist_bookmarks ⇒ Object
62
63
64
|
# File 'lib/pandoru/models/bookmark.rb', line 62
def artist_bookmarks
select(&:artist_bookmark?)
end
|
#find_artist_bookmark(artist_name) ⇒ Object
74
75
76
77
78
|
# File 'lib/pandoru/models/bookmark.rb', line 74
def find_artist_bookmark(artist_name)
artist_bookmarks.find do |bookmark|
bookmark.artist_name&.casecmp(artist_name) == 0
end
end
|
#find_song_bookmark(song_name, artist_name = nil) ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/pandoru/models/bookmark.rb', line 66
def find_song_bookmark(song_name, artist_name = nil)
song_bookmarks.find do |bookmark|
matches_song = bookmark.song_name&.casecmp(song_name) == 0
matches_artist = artist_name.nil? || bookmark.artist_name&.casecmp(artist_name) == 0
matches_song && matches_artist
end
end
|
#song_bookmarks ⇒ Object
58
59
60
|
# File 'lib/pandoru/models/bookmark.rb', line 58
def song_bookmarks
select(&:song_bookmark?)
end
|