Class: Scrobbler::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.
-
#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.
-
#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.
-
#reach ⇒ Object
Returns the value of attribute reach.
-
#release_date ⇒ Object
Returns the value of attribute release_date.
-
#streamable ⇒ Object
needed on top albums for tag.
- #tracks ⇒ Object
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #api_path(version = nil) ⇒ Object
- #image(which = :small) ⇒ Object
-
#initialize(artist, name, o = {}) ⇒ Album
constructor
A new instance of Album.
- #load_info ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(artist, name, o = {}) ⇒ Album
Returns a new instance of Album.
93 94 95 96 97 98 99 100 |
# File 'lib/scrobbler/album.rb', line 93 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.
46 47 48 |
# File 'lib/scrobbler/album.rb', line 46 def artist @artist end |
#artist_mbid ⇒ Object
Returns the value of attribute artist_mbid.
46 47 48 |
# File 'lib/scrobbler/album.rb', line 46 def artist_mbid @artist_mbid end |
#chartposition ⇒ Object
needed for weekly album charts
54 55 56 |
# File 'lib/scrobbler/album.rb', line 54 def chartposition @chartposition end |
#count ⇒ Object
needed on top albums for tag
51 52 53 |
# File 'lib/scrobbler/album.rb', line 51 def count @count end |
#image_large ⇒ Object
Returns the value of attribute image_large.
47 48 49 |
# File 'lib/scrobbler/album.rb', line 47 def image_large @image_large end |
#image_medium ⇒ Object
Returns the value of attribute image_medium.
47 48 49 |
# File 'lib/scrobbler/album.rb', line 47 def image_medium @image_medium end |
#image_small ⇒ Object
Returns the value of attribute image_small.
47 48 49 |
# File 'lib/scrobbler/album.rb', line 47 def image_small @image_small end |
#mbid ⇒ Object
Returns the value of attribute mbid.
46 47 48 |
# File 'lib/scrobbler/album.rb', line 46 def mbid @mbid end |
#name ⇒ Object
Returns the value of attribute name.
46 47 48 |
# File 'lib/scrobbler/album.rb', line 46 def name @name end |
#playcount ⇒ Object
Returns the value of attribute playcount.
46 47 48 |
# File 'lib/scrobbler/album.rb', line 46 def playcount @playcount end |
#rank ⇒ Object
Returns the value of attribute rank.
46 47 48 |
# File 'lib/scrobbler/album.rb', line 46 def rank @rank end |
#reach ⇒ Object
Returns the value of attribute reach.
46 47 48 |
# File 'lib/scrobbler/album.rb', line 46 def reach @reach end |
#release_date ⇒ Object
Returns the value of attribute release_date.
46 47 48 |
# File 'lib/scrobbler/album.rb', line 46 def release_date @release_date end |
#streamable ⇒ Object
needed on top albums for tag
51 52 53 |
# File 'lib/scrobbler/album.rb', line 51 def streamable @streamable end |
#tracks ⇒ Object
127 128 129 130 |
# File 'lib/scrobbler/album.rb', line 127 def tracks load_info if @tracks.nil? @tracks end |
#url ⇒ Object
Returns the value of attribute url.
46 47 48 |
# File 'lib/scrobbler/album.rb', line 46 def url @url end |
Class Method Details
.find(artist, name, o = {}) ⇒ Object
57 58 59 |
# File 'lib/scrobbler/album.rb', line 57 def find(artist, name, o={}) new(artist, name, o) end |
.new_from_xml(xml, doc = nil) ⇒ Object
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 |
# File 'lib/scrobbler/album.rb', line 61 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'] artist = (xml).at(:artist)['name'] if (xml).at(:artist) && (xml).at(:artist)['name'] artist = (xml).at(:artist).inner_html if artist.nil? && (xml).at(:artist) artist = doc.root['artist'] if artist.nil? && doc.root['artist'] a = Album.new(artist, name) a.artist_mbid = (xml).at(:artist)['mbid'] if (xml).at(:artist) && (xml).at(:artist)['mbid'] a.artist_mbid = (xml).at(:artist).at(:mbid).inner_html if a.artist_mbid.nil? && (xml).at(:artist) && (xml).at(:artist).at(:mbid) a.mbid = (xml).at(:mbid).inner_html if (xml).at(:mbid) a.playcount = (xml).at(:playcount).inner_html if (xml).at(:playcount) a.chartposition = (xml).at(:chartposition).inner_html if (xml).at(:chartposition) a.rank = (xml).at(:rank).inner_html if (xml).at(:rank) a.url = (xml/:url).last.inner_html if (xml/:url).size > 1 a.url = (xml).at(:url).inner_html if a.url.nil? && (xml).at(:url) a.reach = (xml).at(:reach).inner_html if (xml).at(:reach) a.image_large = (xml).at(:image).at(:large).inner_html if (xml).at(:image) && (xml).at(:image).at(:large) a.image_medium = (xml).at(:image).at(:medium).inner_html if (xml).at(:image) && (xml).at(:image).at(:medium) a.image_small = (xml).at(:image).at(:small).inner_html if (xml).at(:image) && (xml).at(:image).at(:small) # coverart element used on top albums for tag a.image_large = (xml).at(:coverart).at(:large).inner_html if a.image_large.nil? && (xml).at(:coverart) && (xml).at(:coverart).at(:large) a.image_medium = (xml).at(:coverart).at(:medium).inner_html if a.image_medium.nil? && (xml).at(:coverart) && (xml).at(:coverart).at(:medium) a.image_small = (xml).at(:coverart).at(:small).inner_html if a.image_small.nil? && (xml).at(:coverart) && (xml).at(:coverart).at(:small) # needed on top albums for tag a.count = xml['count'] if xml['count'] a.streamable = xml['streamable'] if xml['streamable'] a end |
Instance Method Details
#api_path(version = nil) ⇒ Object
102 103 104 |
# File 'lib/scrobbler/album.rb', line 102 def api_path(version=nil) "/#{version || API_VERSION}/album/#{CGI::escape(artist)}/#{CGI::escape(name)}" end |
#image(which = :small) ⇒ Object
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/scrobbler/album.rb', line 132 def image(which=:small) which = which.to_s raise ArgumentError unless ['small', 'medium', 'large'].include?(which) img_url = instance_variable_get("@image_#{which}") if img_url.nil? load_info img_url = instance_variable_get("@image_#{which}") end img_url end |
#load_info ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/scrobbler/album.rb', line 106 def load_info doc = self.class.fetch_and_parse("#{api_path}/info.xml") @reach = (doc).at(:reach).inner_html @url = (doc).at(:url).inner_html @release_date = Time.parse((doc).at(:releasedate).inner_html.strip) @image_large = (doc).at(:coverart).at(:large).inner_html @image_medium = (doc).at(:coverart).at(:medium).inner_html @image_small = (doc).at(:coverart).at(:small).inner_html @mbid = (doc).at(:mbid).inner_html @tracks = (doc/:track).inject([]) do |tracks, track| t = Track.new(artist, track['title']) t.artist_mbid = artist_mbid t.album = name t.album_mbid = mbid t.url = (track).at(:url).inner_html t.reach = (track).at(:reach).inner_html tracks << t tracks end end |