Class: AppleMusicLibrary::Track
- Inherits:
-
Object
- Object
- AppleMusicLibrary::Track
- Defined in:
- lib/apple_music_library/track.rb
Constant Summary collapse
- ATTRIBUTES =
‘Artist’, The #artist, #album, and #genre methods return objects rather than strings and have methods like #artist_name to retrieve the strings. ‘Album’, ‘Genre’,
['Track ID', 'Name', 'Kind', 'Size', 'Total Time', 'Track Number', 'Year', 'Date Modified', 'Date Added', 'Bit Rate', 'Sample Rate', 'Play Count', 'Play Date', 'Play Date UTC', 'Rating', 'Album Rating', 'Album Rating Computed', 'Loved', 'Normalization', 'Persistent ID', 'Track Type', 'Location', 'File Folder Count', 'Library Folder Count']
- @@tracks =
{}
Instance Attribute Summary collapse
-
#album ⇒ Object
readonly
Returns the value of attribute album.
-
#artist ⇒ Object
readonly
Returns the value of attribute artist.
-
#genre ⇒ Object
readonly
Returns the value of attribute genre.
Class Method Summary collapse
Instance Method Summary collapse
- #album_name ⇒ Object
- #artist_name ⇒ Object
- #genre_name ⇒ Object
- #id ⇒ Object
-
#initialize(info) ⇒ Track
constructor
A new instance of Track.
- #loved? ⇒ Boolean
- #rated? ⇒ Boolean
- #star_rating ⇒ Object
- #year_name ⇒ Object
Constructor Details
#initialize(info) ⇒ Track
Returns a new instance of Track.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/apple_music_library/track.rb', line 37 def initialize(info) @info = info @artist = Artist.find_or_create(artist_name) @album = Album.find_or_create(@artist, album_name) # if name.match(/Humble.*demo/) # puts "Adding track #{name} to album #{album_name}" # end @genre = Genre.find_or_create(genre_name) if year_name.present? @year = Year.find_or_create(year_name) @year.add_track(self) @decade = Decade.find_or_create_for(year_name) @decade.add_track(self) end @artist.add_track(self) @artist.add_album(@album) @album.add_track(self) @genre.add_track(self) @@tracks[id] = self end |
Instance Attribute Details
#album ⇒ Object (readonly)
Returns the value of attribute album.
5 6 7 |
# File 'lib/apple_music_library/track.rb', line 5 def album @album end |
#artist ⇒ Object (readonly)
Returns the value of attribute artist.
5 6 7 |
# File 'lib/apple_music_library/track.rb', line 5 def artist @artist end |
#genre ⇒ Object (readonly)
Returns the value of attribute genre.
5 6 7 |
# File 'lib/apple_music_library/track.rb', line 5 def genre @genre end |
Class Method Details
.all ⇒ Object
66 67 68 |
# File 'lib/apple_music_library/track.rb', line 66 def self.all @@tracks.values end |
.find(track_id) ⇒ Object
62 63 64 |
# File 'lib/apple_music_library/track.rb', line 62 def self.find(track_id) @@tracks[track_id] end |
.loved ⇒ Object
70 71 72 |
# File 'lib/apple_music_library/track.rb', line 70 def self.loved @loved ||= self.all.select{|t| t.loved?} end |
Instance Method Details
#album_name ⇒ Object
82 83 84 |
# File 'lib/apple_music_library/track.rb', line 82 def album_name @info['Album'] end |
#artist_name ⇒ Object
78 79 80 |
# File 'lib/apple_music_library/track.rb', line 78 def artist_name @info['Artist'] end |
#genre_name ⇒ Object
86 87 88 |
# File 'lib/apple_music_library/track.rb', line 86 def genre_name @info['Genre'] end |
#id ⇒ Object
74 75 76 |
# File 'lib/apple_music_library/track.rb', line 74 def id track_id end |
#loved? ⇒ Boolean
102 103 104 |
# File 'lib/apple_music_library/track.rb', line 102 def loved? loved end |
#rated? ⇒ Boolean
98 99 100 |
# File 'lib/apple_music_library/track.rb', line 98 def rated? > 0 and <= 100 end |
#star_rating ⇒ Object
94 95 96 |
# File 'lib/apple_music_library/track.rb', line 94 def / 20 end |
#year_name ⇒ Object
90 91 92 |
# File 'lib/apple_music_library/track.rb', line 90 def year_name @info['Year'] end |