Class: LastfmItunes::Playlist

Inherits:
Object
  • Object
show all
Defined in:
lib/lastfm-itunes/playlist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Playlist

Returns a new instance of Playlist.



6
7
8
9
10
11
12
13
14
# File 'lib/lastfm-itunes/playlist.rb', line 6

def initialize(args)
  @search = Lastfm::Search.new(
    credentials: args.fetch(:credentials),
    search_class: args.fetch(:search_class, LastfmItunes::Lastfm::Artist),
    name:   args.fetch(:name, nil),
    limit:  args.fetch(:limit, nil))
  @itunes = Itunes.new args.fetch(:itunes_xml_path)
  @tracks = []
end

Instance Attribute Details

#itunesObject (readonly)

Returns the value of attribute itunes.



3
4
5
# File 'lib/lastfm-itunes/playlist.rb', line 3

def itunes
  @itunes
end

#limitObject

Returns the value of attribute limit.



4
5
6
# File 'lib/lastfm-itunes/playlist.rb', line 4

def limit
  @limit
end

#searchObject (readonly)

Returns the value of attribute search.



3
4
5
# File 'lib/lastfm-itunes/playlist.rb', line 3

def search
  @search
end

#tracksObject (readonly)

Returns the value of attribute tracks.



3
4
5
# File 'lib/lastfm-itunes/playlist.rb', line 3

def tracks
  @tracks
end

Instance Method Details

#fetch_tracks(&block) ⇒ Object



16
17
18
19
# File 'lib/lastfm-itunes/playlist.rb', line 16

def fetch_tracks(&block)
  @tracks = @search.my_top_tracks(@itunes.tracks,
                                  &block)
end

#track_pathsObject



21
22
23
# File 'lib/lastfm-itunes/playlist.rb', line 21

def track_paths
  @tracks.map { |t| t.location_path }
end