Class: Scrobbler::Track
Instance Attribute Summary collapse
-
#album ⇒ Object
Returns the value of attribute album.
-
#album_mbid ⇒ Object
Returns the value of attribute album_mbid.
-
#artist ⇒ Object
Returns the value of attribute artist.
-
#artist_mbid ⇒ Object
Returns the value of attribute artist_mbid.
-
#chartposition ⇒ Object
for weekly top tracks.
-
#count ⇒ Object
only seems to be used on top tracks for tag.
-
#date ⇒ Object
Returns the value of attribute date.
-
#date_uts ⇒ Object
Returns the value of attribute date_uts.
-
#image ⇒ Object
only seems to be used on top tracks for tag.
-
#mbid ⇒ Object
Returns the value of attribute mbid.
-
#name ⇒ Object
Returns the value of attribute name.
-
#now_playing ⇒ Object
Returns the value of attribute now_playing.
-
#playcount ⇒ Object
Returns the value of attribute playcount.
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#reach ⇒ Object
Returns the value of attribute reach.
-
#streamable ⇒ Object
Returns the value of attribute streamable.
-
#thumbnail ⇒ Object
only seems to be used on top tracks for tag.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #fans(force = false) ⇒ Object
-
#initialize(artist, name) ⇒ Track
constructor
A new instance of Track.
- #tags(force = false) ⇒ Object
Methods inherited from Base
api_key=, connection, fetch_and_parse, sanitize
Constructor Details
#initialize(artist, name) ⇒ Track
Returns a new instance of Track.
74 75 76 77 78 79 |
# File 'lib/scrobbler/track.rb', line 74 def initialize(artist, name) raise ArgumentError, "Artist is required" if artist.blank? raise ArgumentError, "Name is required" if name.blank? @artist = artist @name = name end |
Instance Attribute Details
#album ⇒ Object
Returns the value of attribute album.
39 40 41 |
# File 'lib/scrobbler/track.rb', line 39 def album @album end |
#album_mbid ⇒ Object
Returns the value of attribute album_mbid.
39 40 41 |
# File 'lib/scrobbler/track.rb', line 39 def album_mbid @album_mbid end |
#artist ⇒ Object
Returns the value of attribute artist.
38 39 40 |
# File 'lib/scrobbler/track.rb', line 38 def artist @artist end |
#artist_mbid ⇒ Object
Returns the value of attribute artist_mbid.
38 39 40 |
# File 'lib/scrobbler/track.rb', line 38 def artist_mbid @artist_mbid end |
#chartposition ⇒ Object
for weekly top tracks
45 46 47 |
# File 'lib/scrobbler/track.rb', line 45 def chartposition @chartposition end |
#count ⇒ Object
only seems to be used on top tracks for tag
42 43 44 |
# File 'lib/scrobbler/track.rb', line 42 def count @count end |
#date ⇒ Object
Returns the value of attribute date.
39 40 41 |
# File 'lib/scrobbler/track.rb', line 39 def date @date end |
#date_uts ⇒ Object
Returns the value of attribute date_uts.
39 40 41 |
# File 'lib/scrobbler/track.rb', line 39 def date_uts @date_uts end |
#image ⇒ Object
only seems to be used on top tracks for tag
42 43 44 |
# File 'lib/scrobbler/track.rb', line 42 def image @image end |
#mbid ⇒ Object
Returns the value of attribute mbid.
38 39 40 |
# File 'lib/scrobbler/track.rb', line 38 def mbid @mbid end |
#name ⇒ Object
Returns the value of attribute name.
38 39 40 |
# File 'lib/scrobbler/track.rb', line 38 def name @name end |
#now_playing ⇒ Object
Returns the value of attribute now_playing.
39 40 41 |
# File 'lib/scrobbler/track.rb', line 39 def @now_playing end |
#playcount ⇒ Object
Returns the value of attribute playcount.
38 39 40 |
# File 'lib/scrobbler/track.rb', line 38 def playcount @playcount end |
#rank ⇒ Object
Returns the value of attribute rank.
38 39 40 |
# File 'lib/scrobbler/track.rb', line 38 def rank @rank end |
#reach ⇒ Object
Returns the value of attribute reach.
38 39 40 |
# File 'lib/scrobbler/track.rb', line 38 def reach @reach end |
#streamable ⇒ Object
Returns the value of attribute streamable.
39 40 41 |
# File 'lib/scrobbler/track.rb', line 39 def streamable @streamable end |
#thumbnail ⇒ Object
only seems to be used on top tracks for tag
42 43 44 |
# File 'lib/scrobbler/track.rb', line 42 def thumbnail @thumbnail end |
#url ⇒ Object
Returns the value of attribute url.
38 39 40 |
# File 'lib/scrobbler/track.rb', line 38 def url @url end |
Class Method Details
.new_from_xml(xml, doc = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/scrobbler/track.rb', line 48 def new_from_xml(xml, doc=nil) artist = xml.at('/artist/name').inner_html if xml.at('/artist/name') artist = xml.at(:artist).inner_html if artist.nil? && xml.at(:artist) name = xml.at(:name).inner_html if xml.at(:name) t = Track.new(artist, name) t.artist_mbid = xml.at(:artist)['mbid'] if xml.at(:artist) && xml.at(:artist)['mbid'] t.artist_mbid = xml.at('/artist/mbid').inner_html if t.artist_mbid.nil? && xml.at('/artist/mbid') t.mbid = xml.at(:mbid).inner_html if xml.at(:mbid) t.playcount = xml.at(:playcount).inner_html if xml.at(:playcount) t.chartposition = xml.at(:chartposition).inner_html if xml.at(:chartposition) t.rank = xml['rank'] if xml['rank'] t.url = xml.at('/url').inner_html if xml.at('/url') t.streamable = xml.at('/streamable').inner_html if xml.at('/streamable') t.count = xml.at('/tagcount').inner_html if xml.at('/tagcount') t.album = xml.at(:album).inner_html if xml.at(:album) t.album_mbid = xml.at(:album)['mbid'] if xml.at(:album) && xml.at(:album)['mbid'] t.date = Time.parse((xml).at(:date).inner_html) if xml.at(:date) t.date_uts = xml.at(:date)['uts'] if xml.at(:date) && xml.at(:date)['uts'] t.thumbnail = xml.at('/image[@size="small"]').inner_html if xml.at('/image[@size="small"]') t.image = xml.at('/image[@size="medium"]').inner_html if xml.at('/image[@size="medium"]') t. = true if xml['nowplaying'] && xml['nowplaying'] == 'true' t. = false unless t. t end |
Instance Method Details
#fans(force = false) ⇒ Object
81 82 83 |
# File 'lib/scrobbler/track.rb', line 81 def fans(force=false) get_instance2('track.gettopfans', :fans, :user, {'artist'=>@artist, 'track'=>@name}, force) end |
#tags(force = false) ⇒ Object
85 86 87 |
# File 'lib/scrobbler/track.rb', line 85 def (force=false) get_instance2('track.gettoptags', :tags, :tag, {'artist'=>@artist, 'track'=>@name}, force) end |