Class: Mostscrobbled::Artist
- Inherits:
-
Object
- Object
- Mostscrobbled::Artist
- Defined in:
- lib/mostscrobbled/artist.rb
Instance Attribute Summary collapse
-
#image_extralarge ⇒ Object
Returns the value of attribute image_extralarge.
-
#image_large ⇒ Object
Returns the value of attribute image_large.
-
#image_medium ⇒ Object
Returns the value of attribute image_medium.
-
#image_mega ⇒ Object
Returns the value of attribute image_mega.
-
#image_small ⇒ Object
Returns the value of attribute image_small.
-
#mbid ⇒ Object
Returns the value of attribute mbid.
-
#name ⇒ Object
Returns the value of attribute name.
-
#playcount ⇒ Object
Returns the value of attribute playcount.
-
#streamable ⇒ Object
Returns the value of attribute streamable.
-
#tagcount ⇒ Object
Returns the value of attribute tagcount.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
-
.build_artist(node) ⇒ Object
Creates an instance of Mostscrobbled::Artist from an xml node returned by the last.fm api.
Instance Method Summary collapse
-
#attributes ⇒ Object
Returns a hash of all the attributes with their names as keys and the values of the attributes as values.
-
#initialize(attrs = {}, *args) ⇒ Artist
constructor
A new instance of Artist.
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_extralarge ⇒ Object
Returns the value of attribute image_extralarge.
4 5 6 |
# File 'lib/mostscrobbled/artist.rb', line 4 def image_extralarge @image_extralarge end |
#image_large ⇒ Object
Returns the value of attribute image_large.
4 5 6 |
# File 'lib/mostscrobbled/artist.rb', line 4 def image_large @image_large end |
#image_medium ⇒ Object
Returns the value of attribute image_medium.
4 5 6 |
# File 'lib/mostscrobbled/artist.rb', line 4 def image_medium @image_medium end |
#image_mega ⇒ Object
Returns the value of attribute image_mega.
4 5 6 |
# File 'lib/mostscrobbled/artist.rb', line 4 def image_mega @image_mega end |
#image_small ⇒ Object
Returns the value of attribute image_small.
4 5 6 |
# File 'lib/mostscrobbled/artist.rb', line 4 def image_small @image_small end |
#mbid ⇒ Object
Returns the value of attribute mbid.
4 5 6 |
# File 'lib/mostscrobbled/artist.rb', line 4 def mbid @mbid end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/mostscrobbled/artist.rb', line 4 def name @name end |
#playcount ⇒ Object
Returns the value of attribute playcount.
4 5 6 |
# File 'lib/mostscrobbled/artist.rb', line 4 def playcount @playcount end |
#streamable ⇒ Object
Returns the value of attribute streamable.
4 5 6 |
# File 'lib/mostscrobbled/artist.rb', line 4 def streamable @streamable end |
#tagcount ⇒ Object
Returns the value of attribute tagcount.
4 5 6 |
# File 'lib/mostscrobbled/artist.rb', line 4 def tagcount @tagcount end |
#url ⇒ Object
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
#attributes ⇒ Object
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 |