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.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
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 60 61 62 |
# 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) @century = Century.find_or_create_for(year_name) @century.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 |
#info ⇒ Object (readonly)
Returns the value of attribute info.
5 6 7 |
# File 'lib/apple_music_library/track.rb', line 5 def info @info end |
Class Method Details
.all ⇒ Object
69 70 71 |
# File 'lib/apple_music_library/track.rb', line 69 def self.all @@tracks.values end |
.find(track_id) ⇒ Object
65 66 67 |
# File 'lib/apple_music_library/track.rb', line 65 def self.find(track_id) @@tracks[track_id] end |
.loved ⇒ Object
73 74 75 |
# File 'lib/apple_music_library/track.rb', line 73 def self.loved @loved ||= self.all.select{|t| t.loved?} end |
Instance Method Details
#album_name ⇒ Object
85 86 87 |
# File 'lib/apple_music_library/track.rb', line 85 def album_name @info['Album'] end |
#artist_name ⇒ Object
81 82 83 |
# File 'lib/apple_music_library/track.rb', line 81 def artist_name @info['Artist'] end |
#genre_name ⇒ Object
89 90 91 |
# File 'lib/apple_music_library/track.rb', line 89 def genre_name @info['Genre'] end |
#id ⇒ Object
77 78 79 |
# File 'lib/apple_music_library/track.rb', line 77 def id track_id end |
#loved? ⇒ Boolean
105 106 107 |
# File 'lib/apple_music_library/track.rb', line 105 def loved? loved end |
#rated? ⇒ Boolean
101 102 103 |
# File 'lib/apple_music_library/track.rb', line 101 def rated? > 0 and <= 100 end |
#star_rating ⇒ Object
97 98 99 |
# File 'lib/apple_music_library/track.rb', line 97 def / 20 end |
#year_name ⇒ Object
93 94 95 |
# File 'lib/apple_music_library/track.rb', line 93 def year_name @info['Year'] end |