Class: AppleMusicLibrary::Playlist

Inherits:
TrackCollection show all
Defined in:
lib/apple_music_library/playlist.rb

Constant Summary collapse

ATTRIBUTES =
[
  'Name',
  'Description',
  'Playlist ID',
  'Playlist Persistent ID',
  'Parent Persistent ID',
  'All Items',
  'Smart Info',
  'Smart Criteria',
  'Playlist Items',
  'Folder'
]
SYSTEM_PLAYLISTS =
[
  'Downloaded',
  'Library',
  'Music',
  'Recently Played'
]
@@playlists =
{}

Instance Attribute Summary collapse

Attributes inherited from TrackCollection

#name, #tracks

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TrackCollection

#add_track, #album_count, find_or_create, #star_rating, #track_count

Constructor Details

#initialize(info) ⇒ Playlist

Returns a new instance of Playlist.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/apple_music_library/playlist.rb', line 31

def initialize(info)
  @info = info

  if folder?
    return PlaylistFolder.new(info)
  end

  super

  load_tracks

  @@playlists[id] = self
end

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



7
8
9
# File 'lib/apple_music_library/playlist.rb', line 7

def info
  @info
end

Class Method Details

.allObject



45
46
47
# File 'lib/apple_music_library/playlist.rb', line 45

def self.all
  @@playlists.values
end

.find_by_name(playlist_name) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/apple_music_library/playlist.rb', line 61

def self.find_by_name(playlist_name)
  results = @@playlists.values.select{|p| p.name == playlist_name}
  if results.size == 1
    return results.first
  end
  results
end

.regularObject



53
54
55
# File 'lib/apple_music_library/playlist.rb', line 53

def self.regular
  @@playlists.values.select{|p| !p.smart? and !p.system?}
end

.smartObject



49
50
51
# File 'lib/apple_music_library/playlist.rb', line 49

def self.smart
  @@playlists.values.select{|p| p.smart?}
end

.systemObject



57
58
59
# File 'lib/apple_music_library/playlist.rb', line 57

def self.system
  @@playlists.values.select{|p| p.system?}
end

Instance Method Details

#folder?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/apple_music_library/playlist.rb', line 79

def folder?
  folder.present?
end

#idObject



69
70
71
# File 'lib/apple_music_library/playlist.rb', line 69

def id
  playlist_persistent_id
end

#smart?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/apple_music_library/playlist.rb', line 83

def smart?
  smart_info.present?
end

#system?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/apple_music_library/playlist.rb', line 87

def system?
  SYSTEM_PLAYLISTS.include?(name)
end

#tokenObject



91
92
93
# File 'lib/apple_music_library/playlist.rb', line 91

def token
  :playlist
end