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

- (Artist) initialize(name)

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

- (Object) chartposition

Returns the value of attribute chartposition



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

def chartposition
  @chartposition
end

- (Object) count

Returns the value of attribute count



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

def count
  @count
end

- (Object) image

Returns the value of attribute image



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

def image
  @image
end

- (Object) match

used for similar artists



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

def match
  @match
end

- (Object) mbid

Returns the value of attribute mbid



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

def mbid
  @mbid
end

- (Object) name

Returns the value of attribute name



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

def name
  @name
end

- (Object) playcount

Returns the value of attribute playcount



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

def playcount
  @playcount
end

- (Object) rank

Returns the value of attribute rank



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

def rank
  @rank
end

- (Object) reach

Returns the value of attribute reach



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

def reach
  @reach
end

- (Object) streamable

Returns the value of attribute streamable



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

def streamable
  @streamable
end

- (Object) thumbnail

Returns the value of attribute thumbnail



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

def thumbnail
  @thumbnail
end

- (Object) url

Returns the value of attribute url



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

def url
  @url
end

Class Method Details

+ (Object) new_from_xml(xml, doc = nil)



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

- (Object) api_path



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

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

- (Object) current_events(format = :ics)

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

- (Object) similar(force = false)



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

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

- (Object) top_albums(force = false)



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

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

- (Object) top_fans(force = false)



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

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

- (Object) top_tags(force = false)



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

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

- (Object) top_tracks(force = false)



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

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