Class Scrobbler::Album
In: lib/scrobbler/album.rb
Parent: Base

Methods

api_path   find   image   load_info   new   new_from_xml   tracks  

Attributes

artist  [RW] 
artist_mbid  [RW] 
chartposition  [RW]  needed for weekly album charts
count  [RW]  needed on top albums for tag
image_large  [RW] 
image_medium  [RW] 
image_small  [RW] 
mbid  [RW] 
name  [RW] 
playcount  [RW] 
rank  [RW] 
reach  [RW] 
release_date  [RW] 
streamable  [RW]  needed on top albums for tag
tracks  [W] 
url  [RW] 

Public Class methods

[Source]

    # File lib/scrobbler/album.rb, line 57
57:       def find(artist, name, o={})
58:         new(artist, name, o)
59:       end

[Source]

     # File lib/scrobbler/album.rb, line 93
 93:     def initialize(artist, name, o={})
 94:       raise ArgumentError, "Artist is required" if artist.blank?
 95:       raise ArgumentError, "Name is required" if name.blank?
 96:       @artist = artist
 97:       @name   = name
 98:       options = {:include_info => false}.merge(o)
 99:       load_info() if options[:include_info]
100:     end

[Source]

    # File lib/scrobbler/album.rb, line 61
61:       def new_from_xml(xml, doc=nil)
62:         name             = (xml).at(:name).inner_html                   if (xml).at(:name)
63:         name             = xml['name']                                  if name.nil? && xml['name']
64:         artist           = (xml).at(:artist)['name']                    if (xml).at(:artist) && (xml).at(:artist)['name']
65:         artist           = (xml).at(:artist).inner_html                 if artist.nil? && (xml).at(:artist)
66:         artist           = doc.root['artist']                           if artist.nil? && doc.root['artist']
67:         a                = Album.new(artist, name)
68:         a.artist_mbid    = (xml).at(:artist)['mbid']                    if (xml).at(:artist) && (xml).at(:artist)['mbid']
69:         a.artist_mbid    = (xml).at(:artist).at(:mbid).inner_html       if a.artist_mbid.nil? && (xml).at(:artist) && (xml).at(:artist).at(:mbid)
70:         a.mbid           = (xml).at(:mbid).inner_html                   if (xml).at(:mbid)
71:         a.playcount      = (xml).at(:playcount).inner_html              if (xml).at(:playcount)
72:         a.chartposition = (xml).at(:chartposition).inner_html          if (xml).at(:chartposition)
73:         a.rank           = (xml).at(:rank).inner_html                   if (xml).at(:rank)
74:         a.url            = (xml/:url).last.inner_html                   if (xml/:url).size > 1
75:         a.url            = (xml).at(:url).inner_html                    if a.url.nil? && (xml).at(:url)
76:         a.reach          = (xml).at(:reach).inner_html                  if (xml).at(:reach)
77:         a.image_large    = (xml).at(:image).at(:large).inner_html       if (xml).at(:image) && (xml).at(:image).at(:large)
78:         a.image_medium   = (xml).at(:image).at(:medium).inner_html      if (xml).at(:image) && (xml).at(:image).at(:medium)
79:         a.image_small    = (xml).at(:image).at(:small).inner_html       if (xml).at(:image) && (xml).at(:image).at(:small)
80:         
81:         # coverart element used on top albums for tag
82:         a.image_large    = (xml).at(:coverart).at(:large).inner_html    if a.image_large.nil? && (xml).at(:coverart) && (xml).at(:coverart).at(:large)
83:         a.image_medium   = (xml).at(:coverart).at(:medium).inner_html   if a.image_medium.nil? && (xml).at(:coverart) && (xml).at(:coverart).at(:medium)
84:         a.image_small    = (xml).at(:coverart).at(:small).inner_html    if a.image_small.nil? && (xml).at(:coverart) && (xml).at(:coverart).at(:small)
85:         
86:         # needed on top albums for tag
87:         a.count          = xml['count'] if xml['count']
88:         a.streamable     = xml['streamable'] if xml['streamable']
89:         a
90:       end

Public Instance methods

[Source]

     # File lib/scrobbler/album.rb, line 102
102:     def api_path
103:       "/#{API_VERSION}/album/#{CGI::escape(artist)}/#{CGI::escape(name)}"
104:     end

[Source]

     # File lib/scrobbler/album.rb, line 132
132:     def image(which=:small)
133:       which = which.to_s
134:       raise ArgumentError unless ['small', 'medium', 'large'].include?(which)      
135:       img_url = instance_variable_get("@image_#{which}")
136:       if img_url.nil?
137:         load_info
138:         img_url = instance_variable_get("@image_#{which}")
139:       end
140:       img_url
141:     end

[Source]

     # File lib/scrobbler/album.rb, line 106
106:     def load_info
107:       doc           = self.class.fetch_and_parse("#{api_path}/info.xml")
108:       @reach        = (doc).at(:reach).inner_html
109:       @url          = (doc).at(:url).inner_html
110:       @release_date = Time.parse((doc).at(:releasedate).inner_html.strip)
111:       @image_large  = (doc).at(:coverart).at(:large).inner_html
112:       @image_medium = (doc).at(:coverart).at(:medium).inner_html
113:       @image_small  = (doc).at(:coverart).at(:small).inner_html
114:       @mbid         = (doc).at(:mbid).inner_html
115:       @tracks       = (doc/:track).inject([]) do |tracks, track|
116:         t             = Track.new(artist, track['title'])
117:         t.artist_mbid = artist_mbid
118:         t.album       = name
119:         t.album_mbid  = mbid
120:         t.url         = (track).at(:url).inner_html
121:         t.reach       = (track).at(:reach).inner_html
122:         tracks << t
123:         tracks
124:       end
125:     end

[Source]

     # File lib/scrobbler/album.rb, line 127
127:     def tracks
128:       load_info if @tracks.nil?
129:       @tracks
130:     end

[Validate]