Class: Rockstar::Tag

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connection, fetch_and_parse, get_instance

Constructor Details

#initialize(name) ⇒ Tag

Returns a new instance of Tag.

Raises:

  • (ArgumentError)


82
83
84
85
# File 'lib/rockstar/tag.rb', line 82

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/rockstar/tag.rb', line 60

def count
  @count
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#urlObject

Returns the value of attribute url.



60
61
62
# File 'lib/rockstar/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/rockstar/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   = Base.fix_url((xml).at(:url).inner_html)
  t
end

.top_tagsObject



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

def top_tags
  doc = fetch_and_parse("tag.getTopTags")
  @top_tags = (doc/"toptags/tag").collect do |tag|
    t       = Tag.new((tag/'name').inner_html)
    t.count = (tag/'count').inner_html
    t.url   = Base.fix_url((tag/'url').inner_html)
    t
  end
end

Instance Method Details

#top_albums(force = false) ⇒ Object



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

def top_albums(force=false)
  get_instance("tag.getTopAlbums", :top_albums, :album, {:tag => @name}, force)
end

#top_artists(force = false) ⇒ Object



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

def top_artists(force=false)
  get_instance("tag.getTopArtists", :top_artists, :artist, {:tag => @name}, force)
end

#top_tracks(force = false) ⇒ Object



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

def top_tracks(force=false)
  get_instance("tag.getTopTracks", :top_tracks, :track, {:tag => @name}, force)
end