Class: Scrobbler::Track

Inherits:
Base
  • Object
show all
Defined in:
lib/scrobbler/track.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connection, fetch_and_parse

Constructor Details

#initialize(artist, name) ⇒ Track

Returns a new instance of Track

Raises:

  • (ArgumentError)


77
78
79
80
81
82
# File 'lib/scrobbler/track.rb', line 77

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

#albumObject

Returns the value of attribute album



39
40
41
# File 'lib/scrobbler/track.rb', line 39

def album
  @album
end

#album_mbidObject

Returns the value of attribute album_mbid



39
40
41
# File 'lib/scrobbler/track.rb', line 39

def album_mbid
  @album_mbid
end

#artistObject

Returns the value of attribute artist



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def artist
  @artist
end

#artist_mbidObject

Returns the value of attribute artist_mbid



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def artist_mbid
  @artist_mbid
end

#chartpositionObject

for weekly top tracks



45
46
47
# File 'lib/scrobbler/track.rb', line 45

def chartposition
  @chartposition
end

#countObject

only seems to be used on top tracks for tag



42
43
44
# File 'lib/scrobbler/track.rb', line 42

def count
  @count
end

#dateObject

Returns the value of attribute date



39
40
41
# File 'lib/scrobbler/track.rb', line 39

def date
  @date
end

#date_utsObject

Returns the value of attribute date_uts



39
40
41
# File 'lib/scrobbler/track.rb', line 39

def date_uts
  @date_uts
end

#imageObject

only seems to be used on top tracks for tag



42
43
44
# File 'lib/scrobbler/track.rb', line 42

def image
  @image
end

#mbidObject

Returns the value of attribute mbid



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def mbid
  @mbid
end

#nameObject

Returns the value of attribute name



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def name
  @name
end

#playcountObject

Returns the value of attribute playcount



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def playcount
  @playcount
end

#rankObject

Returns the value of attribute rank



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def rank
  @rank
end

#reachObject

Returns the value of attribute reach



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def reach
  @reach
end

#streamableObject

Returns the value of attribute streamable



39
40
41
# File 'lib/scrobbler/track.rb', line 39

def streamable
  @streamable
end

#thumbnailObject

only seems to be used on top tracks for tag



42
43
44
# File 'lib/scrobbler/track.rb', line 42

def thumbnail
  @thumbnail
end

#urlObject

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
# 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
end

Instance Method Details

#api_pathObject



84
85
86
# File 'lib/scrobbler/track.rb', line 84

def api_path
  "/#{API_VERSION}/track/#{CGI::escape(artist)}/#{CGI::escape(name)}"
end

#fans(force = false) ⇒ Object



88
89
90
# File 'lib/scrobbler/track.rb', line 88

def fans(force=false)
  get_instance(:fans, :fans, :user, force)
end

#tags(force = false) ⇒ Object



92
93
94
# File 'lib/scrobbler/track.rb', line 92

def tags(force=false)
  get_instance(:toptags, :tags, :tag, force)
end