Class: AppleMusicLibrary::Album

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

Constant Summary collapse

@@albums =
{}

Instance Attribute Summary collapse

Attributes inherited from TrackCollection

#tracks

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TrackCollection

#add_track, #album_count, find_by_name, #star_rating, #track_count

Constructor Details

#initialize(album_name, artist) ⇒ Album

Returns a new instance of Album.



9
10
11
12
# File 'lib/apple_music_library/album.rb', line 9

def initialize(album_name, artist)
  @artist = artist
  super
end

Instance Attribute Details

#artistObject (readonly)

Returns the value of attribute artist.



5
6
7
# File 'lib/apple_music_library/album.rb', line 5

def artist
  @artist
end

Class Method Details

.allObject



14
15
16
# File 'lib/apple_music_library/album.rb', line 14

def self.all
  @@albums.values
end

.find_or_create(artist, album_name) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/apple_music_library/album.rb', line 18

def self.find_or_create(artist, album_name)
  key = "#{artist.name}-#{album_name}"
  if @@albums[key]
    return @@albums[key]
  end
  @@albums[key] = self.new(album_name, artist)
end

.tokenObject



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

def self.token
  :album
end

Instance Method Details

#dumpObject



38
39
40
41
42
43
# File 'lib/apple_music_library/album.rb', line 38

def dump
  puts "#{artist.name} - #{name}"
  tracks.each do |track|
    puts "\t#{track.name}"
  end
end

#idObject



26
27
28
# File 'lib/apple_music_library/album.rb', line 26

def id
  "#{artist.name}-#{album_name}"
end

#nameObject



30
31
32
# File 'lib/apple_music_library/album.rb', line 30

def name
  @album_name
end

#yearObject



34
35
36
# File 'lib/apple_music_library/album.rb', line 34

def year
  @year ||= @tracks.sort_by(&:year).last.year
end