Class: AppleMusicLibrary::TrackCollection
- Inherits:
-
Object
- Object
- AppleMusicLibrary::TrackCollection
show all
- Defined in:
- lib/apple_music_library/track_collection.rb
Constant Summary
collapse
- @@track_collections =
{}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of TrackCollection.
8
9
10
11
|
# File 'lib/apple_music_library/track_collection.rb', line 8
def initialize(name, *args)
@tracks = []
@name = name.present? ? name : 'Unknown'
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4
5
6
|
# File 'lib/apple_music_library/track_collection.rb', line 4
def name
@name
end
|
#tracks ⇒ Object
Returns the value of attribute tracks.
4
5
6
|
# File 'lib/apple_music_library/track_collection.rb', line 4
def tracks
@tracks
end
|
Class Method Details
.all ⇒ Object
13
14
15
|
# File 'lib/apple_music_library/track_collection.rb', line 13
def self.all
@@track_collections[token].values
end
|
.find_by_name(lookup_name) ⇒ Object
17
18
19
|
# File 'lib/apple_music_library/track_collection.rb', line 17
def self.find_by_name(lookup_name)
@@track_collections[token][lookup_name]
end
|
.find_or_create(lookup_name) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/apple_music_library/track_collection.rb', line 21
def self.find_or_create(lookup_name)
if lookup_name.blank?
lookup_name = 'Unknown'
end
unless @@track_collections[token]
@@track_collections[token] = {}
end
if @@track_collections[token][lookup_name]
return @@track_collections[token][lookup_name]
end
@@track_collections[token][lookup_name] = self.new(lookup_name)
end
|
Instance Method Details
#add_track(track) ⇒ Object
37
38
39
40
|
# File 'lib/apple_music_library/track_collection.rb', line 37
def add_track(track)
@tracks << track
end
|
#album_count ⇒ Object
46
47
48
|
# File 'lib/apple_music_library/track_collection.rb', line 46
def album_count
@ablum_count ||= tracks.map(&:album).uniq.count
end
|
#star_rating ⇒ Object
50
51
52
53
|
# File 'lib/apple_music_library/track_collection.rb', line 50
def star_rating
return nil if rated_tracks.empty?
rated_tracks.map(&:star_rating).sum / rated_tracks.size
end
|
#track_count ⇒ Object
42
43
44
|
# File 'lib/apple_music_library/track_collection.rb', line 42
def track_count
@track_count ||= tracks.count
end
|