Class: Rlastfm::Artist

Inherits:
Object
  • Object
show all
Extended by:
Helpers::RemoteAccessor
Includes:
HTTParty, Helpers::Scraper
Defined in:
lib/rlastfm/artist.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::RemoteAccessor

add_mapped_reader, add_reader, memoize_method, remote_reader

Methods included from Helpers::Scraper

included

Constructor Details

#initialize(name) ⇒ Artist

Returns a new instance of Artist.



21
22
23
24
# File 'lib/rlastfm/artist.rb', line 21

def initialize(name)
  self.class.default_params :api_key => Rlastfm.api_key
  @initialized_name = name
end

Class Method Details

.top_twentyObject



12
13
14
15
16
17
18
19
# File 'lib/rlastfm/artist.rb', line 12

def self.top_twenty
  doc = doc_for("/charts/artist")
  top_twenty = doc.at('.mediumImageChart')
  top_twenty.search('tr').map do |artist_row|
    name =  artist_row.search('.subject < a').last
    new name
  end
end

Instance Method Details

#album_by_name(album_name) ⇒ Object



26
27
28
# File 'lib/rlastfm/artist.rb', line 26

def album_by_name(album_name)
  albums.detect {|a| a.name == album_name}
end

#albumsObject



30
31
32
33
34
35
36
# File 'lib/rlastfm/artist.rb', line 30

def albums
  @albums ||= begin
    response = self.class.get('', :query => {:method => "artist.gettopalbums", :artist => name})
    album_collection = response['lfm']['topalbums']['album']
    album_collection.map{|album_attrs| Album.new album_attrs} if album_collection
  end
end

#exists?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/rlastfm/artist.rb', line 38

def exists?
  ! mbid.nil?
end

#rawObject



42
43
44
# File 'lib/rlastfm/artist.rb', line 42

def raw
  @raw ||= remote_sync!
end

#similar_artistsObject



46
47
48
49
50
51
52
# File 'lib/rlastfm/artist.rb', line 46

def similar_artists
  @similar_artists ||= begin
    raw['similar']['artist'].map do |artist|
      Artist.new artist['name']
    end
  end
end