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

api_key=, connection, fetch_and_parse, sanitize

Constructor Details

#initialize(name) ⇒ Tag

Returns a new instance of Tag.

Raises:

  • (ArgumentError)


72
73
74
75
# File 'lib/scrobbler/tag.rb', line 72

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 if xml.at(:count)
  t.url   = xml.at(:url).inner_html
  t
end

Instance Method Details

#api_pathObject



77
78
79
# File 'lib/scrobbler/tag.rb', line 77

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

#top_albums(force = false) ⇒ Object



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

def top_albums(force=false)
  get_instance2('tag.gettopalbums', :top_albums, :album, {'tag'=>@name}, force)
end

#top_artists(force = false) ⇒ Object



81
82
83
# File 'lib/scrobbler/tag.rb', line 81

def top_artists(force=false)
  get_instance2('tag.gettopartists', :top_artists, :artist, {'tag'=>@name}, force)
end

#top_tracks(force = false) ⇒ Object



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

def top_tracks(force=false)
  get_instance2('tag.gettoptracks', :top_tracks, :track, {'tag'=>@name}, force)
end