Class: Mostscrobbled::Artist

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}, *args) ⇒ Artist

Returns a new instance of Artist.



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

def initialize(attrs = {}, *args) 
  super(*args)
  attrs.each { |key,value| send("#{key}=", value) }
end

Instance Attribute Details

#image_extralargeObject

Returns the value of attribute image_extralarge.



4
5
6
# File 'lib/mostscrobbled/artist.rb', line 4

def image_extralarge
  @image_extralarge
end

#image_largeObject

Returns the value of attribute image_large.



4
5
6
# File 'lib/mostscrobbled/artist.rb', line 4

def image_large
  @image_large
end

#image_mediumObject

Returns the value of attribute image_medium.



4
5
6
# File 'lib/mostscrobbled/artist.rb', line 4

def image_medium
  @image_medium
end

#image_megaObject

Returns the value of attribute image_mega.



4
5
6
# File 'lib/mostscrobbled/artist.rb', line 4

def image_mega
  @image_mega
end

#image_smallObject

Returns the value of attribute image_small.



4
5
6
# File 'lib/mostscrobbled/artist.rb', line 4

def image_small
  @image_small
end

#mbidObject

Returns the value of attribute mbid.



4
5
6
# File 'lib/mostscrobbled/artist.rb', line 4

def mbid
  @mbid
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/mostscrobbled/artist.rb', line 4

def name
  @name
end

#playcountObject

Returns the value of attribute playcount.



4
5
6
# File 'lib/mostscrobbled/artist.rb', line 4

def playcount
  @playcount
end

#streamableObject

Returns the value of attribute streamable.



4
5
6
# File 'lib/mostscrobbled/artist.rb', line 4

def streamable
  @streamable
end

#tagcountObject

Returns the value of attribute tagcount.



4
5
6
# File 'lib/mostscrobbled/artist.rb', line 4

def tagcount
  @tagcount
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/mostscrobbled/artist.rb', line 4

def url
  @url
end

Class Method Details

.build_artist(node) ⇒ Object

Creates an instance of Mostscrobbled::Artist from an xml node returned by the last.fm api



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

def self.build_artist(node)
	(artist = Artist.new).tap do
		[:name, :playcount, :tagcount, :mbid, :url, :streamable].each do |attribute|
			artist.send("#{attribute}=", node.xpath(".//#{attribute}").first.content)
		end
		node.xpath(".//image").each do |image_node| # set :image_small, :image_medium, :image_large, :image_extralarge, :image_mega
			artist.send("image_#{image_node.attributes["size"].value}=", image_node.children.first.content) if image_node.children.first
		end
	end
end

Instance Method Details

#attributesObject

Returns a hash of all the attributes with their names as keys and the values of the attributes as values.



24
25
26
# File 'lib/mostscrobbled/artist.rb', line 24

def attributes
  Hash[instance_variables.map { |name| [name[1..-1].to_sym, instance_variable_get(name)] }]
end