Class: LastfmPathFinder::Artist

Inherits:
Object
  • Object
show all
Includes:
Redis::Objects
Defined in:
lib/lastfm_path_finder/artist.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Artist

Returns a new instance of Artist.



11
12
13
14
15
# File 'lib/lastfm_path_finder/artist.rb', line 11

def initialize params
  params.symbolize_keys!
  self.id = params [:id] || (params[:name]).parameterize
  self.name = params[:name]
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/lastfm_path_finder/artist.rb', line 6

def id
  @id
end

Class Method Details

.find_in_lastfm(name) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/lastfm_path_finder/artist.rb', line 33

def self.find_in_lastfm name
  begin
    LastfmPathFinder::Artist.new(LastfmPathFinder::Settings.lastfm_api.artist.get_info(name))
  rescue Lastfm::ApiError => e    
    nil  
  end
  
end

Instance Method Details



19
20
21
22
# File 'lib/lastfm_path_finder/artist.rb', line 19

def related_artists
  related = related_artists_without_lastfm
  related.blank? ? related_artists_in_lastfm : related
end


24
25
26
27
28
29
30
31
# File 'lib/lastfm_path_finder/artist.rb', line 24

def related_artists_in_lastfm
  artists = LastfmPathFinder::Settings.lastfm_api.artist.get_similar(self.name.value)
  related_artists_without_lastfm.clear
  artists.each do |artist|
    related_artists_without_lastfm[artist["name"]] = artist["match"].to_f
  end
  related_artists_without_lastfm
end


17
# File 'lib/lastfm_path_finder/artist.rb', line 17

alias_method :related_artists_without_lastfm, :related_artists