Class: Scrobbler::Tag

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connection, fetch_and_parse

Constructor Details

#initialize(name) ⇒ Tag

Returns a new instance of Tag.

Raises:

  • (ArgumentError)


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

def initialize(name)
  raise ArgumentError, "Name is required" if name.blank?
  @name = name
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



60
61
62
# File 'lib/scrobbler/tag.rb', line 60

def count
  @count
end

#nameObject

Returns the value of attribute name.



60
61
62
# File 'lib/scrobbler/tag.rb', line 60

def name
  @name
end

#urlObject

Returns the value of attribute url.



60
61
62
# File 'lib/scrobbler/tag.rb', line 60

def url
  @url
end

Class Method Details

.new_from_xml(xml, doc = nil) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/scrobbler/tag.rb', line 63

def new_from_xml(xml, doc=nil)
  name    = (xml).at(:name).inner_html
  t       = Tag.new(name)
  t.count = (xml).at(:count).inner_html
  t.url   = (xml).at(:url).inner_html
  t
end

.top_tagsObject



71
72
73
74
75
76
77
78
79
80
# File 'lib/scrobbler/tag.rb', line 71

def top_tags
  doc = fetch_and_parse("/#{API_VERSION}/tag/toptags.xml")
  @top_tags = (doc/:tag).inject([]) do |tags, tag|
    t       = Tag.new(tag['name'])
    t.count = tag['count']
    t.url   = tag['url']
    tags << t
    tags
  end
end

Instance Method Details

#api_path(version = nil) ⇒ Object



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

def api_path(version=nil)
  "/#{version || API_VERSION}/tag/#{CGI::escape(name)}"
end

#top_albums(force = false) ⇒ Object



96
97
98
# File 'lib/scrobbler/tag.rb', line 96

def top_albums(force=false)
  get_instance(:topalbums, :top_albums, :album, force)
end

#top_artists(force = false) ⇒ Object



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

def top_artists(force=false)
  get_instance(:topartists, :top_artists, :artist, force)
end

#top_tracks(force = false) ⇒ Object



100
101
102
# File 'lib/scrobbler/tag.rb', line 100

def top_tracks(force=false)
  get_instance(:toptracks, :top_tracks, :track, force)
end