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
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

#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

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

.allObject



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

.lovedObject



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_nameObject



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

def album_name
  @info['Album']
end

#artist_nameObject



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

def artist_name
  @info['Artist']
end

#genre_nameObject



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

def genre_name
  @info['Genre']
end

#idObject



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

def id
  track_id
end

#loved?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/apple_music_library/track.rb', line 105

def loved?
  loved
end

#rated?Boolean

Returns:

  • (Boolean)


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

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

#star_ratingObject



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

def star_rating
  rating / 20
end

#year_nameObject



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

def year_name
  @info['Year']
end