Class: Pandoru::Models::BookmarkList

Inherits:
Collection show all
Defined in:
lib/pandoru/models/bookmark.rb

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

Constructor Details

This class inherits a constructor from Pandoru::Models::Collection

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)
  
  # Add song bookmarks
  if data['songs']
    Bookmark.from_json_list(api_client, data['songs']).each do |bookmark|
      instance << bookmark
    end
  end

  # Add artist bookmarks (ensure song_name is nil for artists)
  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_bookmarksObject



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_bookmarksObject



58
59
60
# File 'lib/pandoru/models/bookmark.rb', line 58

def song_bookmarks
  select(&:song_bookmark?)
end