Class: Rockstar::Album
Instance Attribute Summary collapse
-
#artist ⇒ Object
Returns the value of attribute artist.
-
#artist_mbid ⇒ Object
Returns the value of attribute artist_mbid.
-
#chartposition ⇒ Object
needed for weekly album charts.
-
#content ⇒ Object
Returns the value of attribute content.
-
#count ⇒ Object
needed on top albums for tag.
-
#image_large ⇒ Object
Returns the value of attribute image_large.
-
#image_medium ⇒ Object
Returns the value of attribute image_medium.
-
#image_small ⇒ Object
Returns the value of attribute image_small.
-
#images ⇒ Object
Returns the value of attribute images.
-
#mbid ⇒ Object
Returns the value of attribute mbid.
-
#name ⇒ Object
Returns the value of attribute name.
-
#playcount ⇒ Object
Returns the value of attribute playcount.
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#release_date ⇒ Object
Returns the value of attribute release_date.
-
#streamable ⇒ Object
needed on top albums for tag.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #image(which = :small) ⇒ Object
-
#initialize(artist, name, o = {}) ⇒ Album
constructor
A new instance of Album.
- #load_info(xml = nil) ⇒ Object
- #tracks ⇒ Object
Methods inherited from Base
connection, fetch_and_parse, get_instance
Constructor Details
#initialize(artist, name, o = {}) ⇒ Album
Returns a new instance of Album.
47 48 49 50 51 52 53 54 55 |
# File 'lib/rockstar/album.rb', line 47 def initialize(artist, name, o={}) raise ArgumentError, "Artist is required" if artist.blank? raise ArgumentError, "Name is required" if name.blank? @artist = artist @name = name = {:include_info => false}.merge(o) load_info if [:include_info] end |
Instance Attribute Details
#artist ⇒ Object
Returns the value of attribute artist.
19 20 21 |
# File 'lib/rockstar/album.rb', line 19 def artist @artist end |
#artist_mbid ⇒ Object
Returns the value of attribute artist_mbid.
19 20 21 |
# File 'lib/rockstar/album.rb', line 19 def artist_mbid @artist_mbid end |
#chartposition ⇒ Object
needed for weekly album charts
26 27 28 |
# File 'lib/rockstar/album.rb', line 26 def chartposition @chartposition end |
#content ⇒ Object
Returns the value of attribute content.
20 21 22 |
# File 'lib/rockstar/album.rb', line 20 def content @content end |
#count ⇒ Object
needed on top albums for tag
23 24 25 |
# File 'lib/rockstar/album.rb', line 23 def count @count end |
#image_large ⇒ Object
Returns the value of attribute image_large.
20 21 22 |
# File 'lib/rockstar/album.rb', line 20 def image_large @image_large end |
#image_medium ⇒ Object
Returns the value of attribute image_medium.
20 21 22 |
# File 'lib/rockstar/album.rb', line 20 def image_medium @image_medium end |
#image_small ⇒ Object
Returns the value of attribute image_small.
20 21 22 |
# File 'lib/rockstar/album.rb', line 20 def image_small @image_small end |
#images ⇒ Object
Returns the value of attribute images.
20 21 22 |
# File 'lib/rockstar/album.rb', line 20 def images @images end |
#mbid ⇒ Object
Returns the value of attribute mbid.
19 20 21 |
# File 'lib/rockstar/album.rb', line 19 def mbid @mbid end |
#name ⇒ Object
Returns the value of attribute name.
19 20 21 |
# File 'lib/rockstar/album.rb', line 19 def name @name end |
#playcount ⇒ Object
Returns the value of attribute playcount.
19 20 21 |
# File 'lib/rockstar/album.rb', line 19 def playcount @playcount end |
#rank ⇒ Object
Returns the value of attribute rank.
19 20 21 |
# File 'lib/rockstar/album.rb', line 19 def rank @rank end |
#release_date ⇒ Object
Returns the value of attribute release_date.
19 20 21 |
# File 'lib/rockstar/album.rb', line 19 def release_date @release_date end |
#streamable ⇒ Object
needed on top albums for tag
23 24 25 |
# File 'lib/rockstar/album.rb', line 23 def streamable @streamable end |
#summary ⇒ Object
Returns the value of attribute summary.
20 21 22 |
# File 'lib/rockstar/album.rb', line 20 def summary @summary end |
#url ⇒ Object
Returns the value of attribute url.
19 20 21 |
# File 'lib/rockstar/album.rb', line 19 def url @url end |
Class Method Details
.find(artist, name, o = {}) ⇒ Object
29 30 31 |
# File 'lib/rockstar/album.rb', line 29 def find(artist, name, o={}) new(artist, name, o) end |
.new_from_xml(xml, doc = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rockstar/album.rb', line 33 def new_from_xml(xml, doc=nil) name = (xml).at(:name).inner_html if (xml).at(:name) name = xml['name'] if name.nil? && xml['name'] name = xml.at(:title).inner_html if name.nil? && (xml).at(:title) artist = (xml).at(:artist).at(:name).inner_html if (xml).at(:artist) && (xml).at(:artist).at(:name) artist = (xml).at(:artist).inner_html if artist.nil? && (xml).at(:artist) artist = doc.root['artist'] if artist.nil? && doc && doc.root['artist'] album = Album.new(artist, name) album.load_info(xml) album end |
Instance Method Details
#image(which = :small) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/rockstar/album.rb', line 100 def image(which=:small) which = which.to_s raise ArgumentError unless ['small', 'medium', 'large', 'extralarge'].include?(which) if (self.images.nil?) load_info end self.images[which] end |
#load_info(xml = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rockstar/album.rb', line 57 def load_info(xml=nil) unless xml doc = self.class.fetch_and_parse("album.getInfo", {:artist => @artist, :album =>@name}) xml = (doc / :album).first end return self if xml.nil? self.artist_mbid = (xml).at(:artist)['mbid'] if (xml).at(:artist) && (xml).at(:artist)['mbid'] self.artist_mbid = (xml).at(:artist).at(:mbid).inner_html if artist_mbid.nil? && (xml).at(:artist) && (xml).at(:artist).at(:mbid) self.mbid = (xml).at(:mbid).inner_html if (xml).at(:mbid) self.playcount = (xml).at(:playcount).inner_html if (xml).at(:playcount) self.rank = xml['rank'] if xml['rank'] self.rank = (xml).at(:rank).inner_html if (xml).at(:rank) if rank.nil? self.url = Base.fix_url((xml).at(:url).inner_html) if (xml).at(:url) self.summary = (xml).at(:summary).to_plain_text if (xml).at(:summary) self.content = (xml).at(:content).to_plain_text if (xml).at(:content) self.release_date = Base.parse_time((xml).at(:releasedate).inner_html.strip) if (xml).at(:releasedate) self.chartposition = rank self.images = {} (xml/'image').each {|image| self.images[image['size']] = image.inner_html if self.images[image['size']].nil? } self.image_large = images['large'] self.image_medium = images['medium'] self.image_small = images['small'] # needed on top albums for tag self.count = xml['count'] if xml['count'] self.streamable = xml['streamable'] if xml['streamable'] self end |
#tracks ⇒ Object
95 96 97 98 |
# File 'lib/rockstar/album.rb', line 95 def tracks warn "[DEPRECATION] `tracks` is deprecated. The current api doesn't offer this function" [] end |