Class: LastFm::Artist

Inherits:
Base
  • Object
show all
Defined in:
lib/last_fm/models/artist.rb

Instance Method Summary collapse

Methods inherited from Base

#attributes=, create_from_hash, #get_xml_attributes, #method_missing, #methods, #name, #name=, search

Constructor Details

#initialize(name) ⇒ Artist

Returns a new instance of Artist.



4
5
6
7
# File 'lib/last_fm/models/artist.rb', line 4

def initialize(name)
  super(name)
  @attributes = self.info if @attributes == {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class LastFm::Base

Instance Method Details

#album(album_name) ⇒ Object



53
54
55
# File 'lib/last_fm/models/artist.rb', line 53

def album(album_name)
  Album.search(@name, album_name)
end

#eventsObject

Work on event object



23
24
25
26
27
# File 'lib/last_fm/models/artist.rb', line 23

def events
  lfm_path = "artist.getevents&artist=#{@name}"
  lfm_data = LastFm::fetch_data(lfm_path)
  return Event.create_from_hash(Hash.from_xml(lfm_data)['lfm']['events']['event'])  
end

#infoObject



9
10
11
12
13
# File 'lib/last_fm/models/artist.rb', line 9

def info
  lfm_path = "artist.getinfo&artist=#{@name}"
  lfm_data = LastFm::fetch_data(lfm_path)
  return Hash.from_xml(lfm_data)['lfm']['artist']
end

#similar(limit = 7) ⇒ Object



29
30
31
32
33
# File 'lib/last_fm/models/artist.rb', line 29

def similar(limit = 7)
  lfm_path = "artist.getsimilar&artist=#{@name}&limit=#{limit}"
  lfm_data = LastFm::fetch_data(lfm_path)   
  return Event.create_from_hash(Hash.from_xml(lfm_data)['lfm']['similarartists']['artist'])   
end

#top_albumsObject

Work on album object



36
37
38
39
40
# File 'lib/last_fm/models/artist.rb', line 36

def top_albums       
  lfm_path = "artist.topAlbums&artist=#{@name}"
  lfm_data = LastFm::fetch_data(lfm_path)
  return Album.create_from_hash(Hash.from_xml(lfm_data)['lfm']['topalbums']['album'])
end

#top_tagsObject

Work on tag object



16
17
18
19
20
# File 'lib/last_fm/models/artist.rb', line 16

def top_tags
  lfm_path = "artist.getTopTags&artist=#{@name}"
  lfm_data = LastFm::fetch_data(lfm_path)
  return  Tag.create_from_hash(Hash.from_xml(lfm_data)['lfm']['toptags']['tag']) 
end

#top_tracksObject

work on track object



43
44
45
46
47
# File 'lib/last_fm/models/artist.rb', line 43

def top_tracks
  lfm_path = "artist.topTracks&artist=#{@name}"
  lfm_data = LastFm::fetch_data(lfm_path)
  return Track.create_from_hash(Hash.from_xml(lfm_data)['lfm']['toptracks']['track'])
end

#track(track_name) ⇒ Object



49
50
51
# File 'lib/last_fm/models/artist.rb', line 49

def track(track_name)
  Track.search(@name, track_name)
end