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, get, maybe_streamable_attribute, maybe_streamable_node, post_request, request, sanitize, secret=

Constructor Details

#initialize(name, data = {}) ⇒ Tag

Returns a new instance of Tag.

Raises:

  • (ArgumentError)


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

def initialize(name, data={})
  raise ArgumentError, "Name is required" if name.blank?
  @name = name
  @url = data[:url] unless data[:url].nil?
  @count = data[:count] unless data[:count].nil?
  @streamable = data[:streamable] unless data[:streamable].nil?
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

#streamableObject

Returns the value of attribute streamable.



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

def streamable
  @streamable
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) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/scrobbler/tag.rb', line 63

def new_from_xml(xml)
  data = {}
  xml.children.each do |child|
    data[:name] = child.content if child.name == 'name'
    data[:count] = child.content.to_i if child.name == 'count'
    data[:url] = child.content if child.name == 'url'
    if child.name == 'streamable'
      if ['1', 'true'].include?(child.content)
        data[:streamable] = true
      else
        data[:streamable] = false
      end
    end
  end
  
  Tag.new(data[:name], data)
end

.top_tagsObject



102
103
104
# File 'lib/scrobbler/tag.rb', line 102

def Tag.top_tags
    self.get('tag.gettoptags', :toptags, :tag)
end

Instance Method Details

#similar(force = false) ⇒ Object

Search for tags similar to this one. Returns tags ranked by similarity, based on listening data.



108
109
110
111
# File 'lib/scrobbler/tag.rb', line 108

def similar(force=false)
    params = {:tag => @name}
    get_response('tag.getsimilar', :similar, 'similartags', 'tag', params, force)
end

#top_albums(force = false) ⇒ Object



94
95
96
# File 'lib/scrobbler/tag.rb', line 94

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

#top_artists(force = false) ⇒ Object



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

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

#top_tracks(force = false) ⇒ Object



98
99
100
# File 'lib/scrobbler/tag.rb', line 98

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