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

- (Tag) initialize(name)

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

- (Object) count

Returns the value of attribute count



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

def count
  @count
end

- (Object) name

Returns the value of attribute name



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

def name
  @name
end

- (Object) url

Returns the value of attribute url



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

def url
  @url
end

Class Method Details

+ (Object) new_from_xml(xml, doc = nil)



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

+ (Object) top_tags



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

- (Object) api_path



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

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

- (Object) top_albums(force = false)



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

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

- (Object) top_artists(force = false)



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

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

- (Object) top_tracks(force = false)



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

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