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
- #api_path(version = nil) ⇒ Object
- #fans(force = false) ⇒ Object
-
#initialize(artist, name) ⇒ Track
constructor
A new instance of Track.
- #tags(force = false) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(artist, name) ⇒ Track
Returns a new instance of Track.
79 80 81 82 83 84 |
# File 'lib/scrobbler/track.rb', line 79 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 72 73 74 75 76 |
# File 'lib/scrobbler/track.rb', line 48 def new_from_xml(xml, doc=nil) 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'] name = (xml).at(:name).inner_html if (xml).at(:name) name = xml['name'] if name.nil? && xml['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).at(:mbid).inner_html if t.artist_mbid.nil? && (xml).at(:artist) && (xml).at(:artist).at(: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).at(:rank).inner_html if (xml).at(:rank) t.url = (xml/:url).last.inner_html if (xml/:url).size > 1 t.url = (xml).at(:url).inner_html if t.url.nil? && (xml).at(:url) t.streamable = (xml).at(:track)['streamable'] if (xml).at(:track) && (xml).at(:track)['streamable'] t.streamable = xml['streamable'] if t.streamable.nil? && xml['streamable'] t.count = xml['count'] if xml['count'] 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(:thumbnail).inner_html if (xml).at(:thumbnail) t.image = (xml).at(:image).inner_html if (xml).at(:image) t.reach = (xml).at(:reach).inner_html if (xml).at(:reach) t. = xml['nowplaying'] ? true : false t end |
Instance Method Details
#api_path(version = nil) ⇒ Object
86 87 88 |
# File 'lib/scrobbler/track.rb', line 86 def api_path(version=nil) "/#{version || API_VERSION}/track/#{CGI::escape(artist)}/#{CGI::escape(name)}" end |
#fans(force = false) ⇒ Object
90 91 92 |
# File 'lib/scrobbler/track.rb', line 90 def fans(force=false) get_instance(:fans, :fans, :user, force) end |
#tags(force = false) ⇒ Object
94 95 96 |
# File 'lib/scrobbler/track.rb', line 94 def (force=false) get_instance(:toptags, :tags, :tag, force) end |