Class: AppleMusicLibrary::Track

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#albumObject (readonly)

Returns the value of attribute album.



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

def album
  @album
end

#artistObject (readonly)

Returns the value of attribute artist.



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

def artist
  @artist
end

#genreObject (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

.allObject



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

.lovedObject



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_nameObject



82
83
84
# File 'lib/apple_music_library/track.rb', line 82

def album_name
  @info['Album']
end

#artist_nameObject



78
79
80
# File 'lib/apple_music_library/track.rb', line 78

def artist_name
  @info['Artist']
end

#genre_nameObject



86
87
88
# File 'lib/apple_music_library/track.rb', line 86

def genre_name
  @info['Genre']
end

#idObject



74
75
76
# File 'lib/apple_music_library/track.rb', line 74

def id
  track_id
end

#loved?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/apple_music_library/track.rb', line 102

def loved?
  loved
end

#rated?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/apple_music_library/track.rb', line 98

def rated?
  rating > 0 and rating <= 100
end

#star_ratingObject



94
95
96
# File 'lib/apple_music_library/track.rb', line 94

def star_rating
  rating / 20
end

#year_nameObject



90
91
92
# File 'lib/apple_music_library/track.rb', line 90

def year_name
  @info['Year']
end