Class: Scrobbler::Artist

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connection, fetch_and_parse

Constructor Details

#initialize(name) ⇒ Artist

Returns a new instance of Artist.

Raises:

  • (ArgumentError)


92
93
94
95
# File 'lib/scrobbler/artist.rb', line 92

def initialize(name)
  raise ArgumentError, "Name is required" if name.blank?
  @name = name
end

Instance Attribute Details

#chartpositionObject

Returns the value of attribute chartposition.



62
63
64
# File 'lib/scrobbler/artist.rb', line 62

def chartposition
  @chartposition
end

#countObject

Returns the value of attribute count.



61
62
63
# File 'lib/scrobbler/artist.rb', line 61

def count
  @count
end

#imageObject

Returns the value of attribute image.



61
62
63
# File 'lib/scrobbler/artist.rb', line 61

def image
  @image
end

#matchObject

used for similar artists



65
66
67
# File 'lib/scrobbler/artist.rb', line 65

def match
  @match
end

#mbidObject

Returns the value of attribute mbid.



61
62
63
# File 'lib/scrobbler/artist.rb', line 61

def mbid
  @mbid
end

#nameObject

Returns the value of attribute name.



61
62
63
# File 'lib/scrobbler/artist.rb', line 61

def name
  @name
end

#playcountObject

Returns the value of attribute playcount.



61
62
63
# File 'lib/scrobbler/artist.rb', line 61

def playcount
  @playcount
end

#rankObject

Returns the value of attribute rank.



61
62
63
# File 'lib/scrobbler/artist.rb', line 61

def rank
  @rank
end

#reachObject

Returns the value of attribute reach.



61
62
63
# File 'lib/scrobbler/artist.rb', line 61

def reach
  @reach
end

#streamableObject

Returns the value of attribute streamable.



61
62
63
# File 'lib/scrobbler/artist.rb', line 61

def streamable
  @streamable
end

#thumbnailObject

Returns the value of attribute thumbnail.



61
62
63
# File 'lib/scrobbler/artist.rb', line 61

def thumbnail
  @thumbnail
end

#urlObject

Returns the value of attribute url.



61
62
63
# File 'lib/scrobbler/artist.rb', line 61

def url
  @url
end

Class Method Details

.new_from_xml(xml, doc = nil) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/scrobbler/artist.rb', line 68

def new_from_xml(xml, doc=nil)
  name             = (xml).at(:name).inner_html           if (xml).at(:name)
  # occasionally name can be found in root of artist element (<artist name="">) rather than as an element (<name>)
  name             = xml['name']                          if name.nil? && xml['name']
  a                = Artist.new(name)
  a.mbid           = (xml).at(:mbid).inner_html           if (xml).at(:mbid)
  a.playcount      = (xml).at(:playcount).inner_html      if (xml).at(:playcount)
  a.rank           = (xml).at(:rank).inner_html           if (xml).at(:rank)
  a.url            = (xml).at(:url).inner_html            if (xml).at(:url)
  a.thumbnail      = (xml).at(:thumbnail).inner_html      if (xml).at(:thumbnail)
  a.thumbnail      = (xml).at(:image_small).inner_html    if a.thumbnail.nil? && (xml).at(:image_small)
  a.image          = (xml).at(:image).inner_html          if (xml).at(:image)
  a.reach          = (xml).at(:reach).inner_html          if (xml).at(:reach)
  a.match          = (xml).at(:match).inner_html          if (xml).at(:match)
  a.chartposition = (xml).at(:chartposition).inner_html  if (xml).at(:chartposition)

  # in top artists for tag
  a.count          = xml['count']                         if xml['count']
  a.streamable     = xml['streamable']                    if xml['streamable']
  a.streamable     = (xml).at(:streamable).inner_html == '1' ? 'yes' : 'no' if a.streamable.nil? && (xml).at(:streamable)
  a
end

Instance Method Details

#api_pathObject



97
98
99
# File 'lib/scrobbler/artist.rb', line 97

def api_path
  "/#{API_VERSION}/artist/#{CGI::escape(name)}"
end

#current_events(format = :ics) ⇒ Object

Raises:

  • (ArgumentError)


101
102
103
104
105
# File 'lib/scrobbler/artist.rb', line 101

def current_events(format=:ics)
  format = :ics if format.to_s == 'ical'
  raise ArgumentError unless ['ics', 'rss'].include?(format.to_s)
  "#{API_URL.chop}#{api_path}/events.#{format}"
end

#similar(force = false) ⇒ Object



107
108
109
# File 'lib/scrobbler/artist.rb', line 107

def similar(force=false)
  get_instance(:similar, :similar, :artist, force)
end

#top_albums(force = false) ⇒ Object



119
120
121
# File 'lib/scrobbler/artist.rb', line 119

def top_albums(force=false)
  get_instance(:topalbums, :top_albums, :album, force)
end

#top_fans(force = false) ⇒ Object



111
112
113
# File 'lib/scrobbler/artist.rb', line 111

def top_fans(force=false)
  get_instance(:fans, :top_fans, :user, force)
end

#top_tags(force = false) ⇒ Object



123
124
125
# File 'lib/scrobbler/artist.rb', line 123

def top_tags(force=false)
  get_instance(:toptags, :top_tags, :tag, force)
end

#top_tracks(force = false) ⇒ Object



115
116
117
# File 'lib/scrobbler/artist.rb', line 115

def top_tracks(force=false)
  get_instance(:toptracks, :top_tracks, :track, force)
end