Class: LastFM::Tag

Inherits:
Struct
  • Object
show all
Defined in:
lib/lastfm/tag.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

from_xml, inherited, #initialize, package, #to_json

Constructor Details

This class inherits a constructor from LastFM::Struct

Instance Attribute Details

#countFixnum

Returns the current value of count.

Returns:

  • (Fixnum)

    the current value of count


9
10
11
# File 'lib/lastfm/tag.rb', line 9

def count
  @count
end

#nameString

Returns the current value of name.

Returns:

  • (String)

    the current value of name


9
10
11
# File 'lib/lastfm/tag.rb', line 9

def name
  @name
end

#reachFixnum

Returns the current value of reach.

Returns:

  • (Fixnum)

    the current value of reach


9
10
11
# File 'lib/lastfm/tag.rb', line 9

def reach
  @reach
end

#streamableBoolean

Returns the current value of streamable.

Returns:

  • (Boolean)

    the current value of streamable


9
10
11
# File 'lib/lastfm/tag.rb', line 9

def streamable
  @streamable
end

#urlString

Returns the current value of url.

Returns:

  • (String)

    the current value of url


9
10
11
# File 'lib/lastfm/tag.rb', line 9

def url
  @url
end

#wikiLastFM::Wiki

Returns the current value of wiki.

Returns:


9
10
11
# File 'lib/lastfm/tag.rb', line 9

def wiki
  @wiki
end

Class Method Details

.get_info(params) ⇒ LastFM::Tag

Get the metadata for a tag.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :tag (String, required)

    the tag name

  • :lang (String, optional)

    the language to return the summary in, expressed as an ISO 639 alpha-2 code

Returns:

  • (LastFM::Tag)

    tag constructed from the metadata contained in the response

See Also:


37
38
39
40
# File 'lib/lastfm/tag.rb', line 37

def get_info( params )
  xml = LastFM.get( "tag.getInfo", params )
  LastFM::Tag.from_xml( xml )
end

.get_similar(params) ⇒ Array<LastFM::Tag>

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

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • tag (String, required)

    the tag name

Returns:

  • (Array<LastFM::Tag>)

    similar tags, ordered by similarity

See Also:


47
48
49
50
51
52
# File 'lib/lastfm/tag.rb', line 47

def get_similar( params )
  xml = LastFM.get( "tag.getSimilar", params )
  xml.find('similartags/tag').map do |tag|
    LastFM::Tag.from_xml( tag )
  end
end

.get_top_albums(params) ⇒ Array[LastFM::Album]

Get the top albums tagged with a tag, ordered by tag count.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :tag (String, required)

    the tag name

  • :page (Fixnum, optional)

    the page number to fetch. defaults to first page

  • :limit (Fixnum, optional)

    the number of results to fetch per page. defaults to 50

Returns:

  • (Array[LastFM::Album])

    list of albums, ordered by tag count

See Also:


61
62
63
64
65
66
# File 'lib/lastfm/tag.rb', line 61

def get_top_albums( params )
  xml = LastFM.get( "tag.getTopAlbums", params )
  xml.find('topalbums/album').map do |album|
    LastFM::Album.from_xml( album )
  end
end

.get_top_artists(params) ⇒ Array[LastFM::Artist]

Get the top artists tagged with a tag, ordered by tag count.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :tag (String, required)

    the tag name

  • :page (Fixnum, optional)

    the page number to fetch. defaults to first page

  • :limit (Fixnum, optional)

    the number of results to fetch per page. defaults to 50

Returns:

See Also:


75
76
77
78
79
80
# File 'lib/lastfm/tag.rb', line 75

def get_top_artists( params )
  xml = LastFM.get( "tag.getTopArtists", params )
  xml.find('topartists/artist').map do |artist|
    LastFM::Artist.from_xml( artist )
  end
end

.get_top_tagsArray<LastFM::Tag>

Fetches the top global tags on Last.fm, sorted by popularity (number of times used).

Returns:

  • (Array<LastFM::Tag>)

    list of tags ordered by popularity

See Also:


86
87
88
89
90
91
# File 'lib/lastfm/tag.rb', line 86

def get_top_tags
  xml = LastFM.get( "tag.getTopTags" )
  xml.find('toptags/tag').map do |tag|
    LastFM::Tag.from_xml( tag )
  end
end

.get_top_tracks(params) ⇒ Array[LastFM::Track]

Get the top tracks tagged with a tag, ordered by tag count.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :tag (String, required)

    the tag name

  • :page (Fixnum, optional)

    the page number to fetch. defaults to first page

  • :limit (Fixnum, optional)

    the number of results to fetch per page. defaults to 50

Returns:

  • (Array[LastFM::Track])

    list of tracks, ordered by tag count

See Also:


100
101
102
103
104
105
# File 'lib/lastfm/tag.rb', line 100

def get_top_tracks( params )
  xml = LastFM.get( "tag.getTopTracks", params )
  xml.find('toptracks/track').map do |track|
    LastFM::Track.from_xml( track )
  end
end

.get_weekly_artist_chart(params) ⇒ Object

Get an artist chart for a tag, for a given date range. If no date range is supplied, it will return the most recent artist chart for this tag.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :tag (String, required)

    the tag name

  • :from (String, optional)

    date at which the chart should start from (see: Tag.get_weekly_chart_list)

  • :to (String, optional)

    date at which the chart should end on (see: Tag.get_weekly_chart_list)

  • :limit (Fixnum, optional)

    the number of results to fetch. defaults to 50

See Also:


115
116
117
# File 'lib/lastfm/tag.rb', line 115

def get_weekly_artist_chart( params )
  LastFM.get( "tag.getWeeklyArtistChart", params )
end

.get_weekly_chart_list(params) ⇒ Object

Get a list of available charts for this tag, expressed as date ranges which can be sent to the chart services.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :tag (String, required)

    the tag name

See Also:


124
125
126
# File 'lib/lastfm/tag.rb', line 124

def get_weekly_chart_list( params )
  LastFM.get( "tag.getWeeklyChartList", params )
end

.search(params) ⇒ Array<LastFM::Tag>

Search for a tag by name. Returns matches sorted by relevance.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :tag (String, required)

    the tag name

  • :page (Fixnum, optional)

    the page number to fetch. defaults to first page

  • :limit (Fixnum, optional)

    the number of results to fetch per page. defaults to 50

Returns:

  • (Array<LastFM::Tag>)

    list of tags sorted by relevance

See Also:


135
136
137
138
139
140
# File 'lib/lastfm/tag.rb', line 135

def search( params )
  xml = LastFM.get( "tag.search", params )
  xml.find('results/tagmatches/tag').map do |tag|
    LastFM::Tag.from_xml( tag )
  end
end

Instance Method Details

#update_from_node(node) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lastfm/tag.rb', line 11

def update_from_node(node)
  case node.name.to_sym
    when :name
      self.name = node.content
    when :url
      self.url = node.content
    when :reach
      self.reach = node.content.to_i
    when :count, :taggings
      self.count = node.content.to_i
    when :streamable
      self.streamable = (node.content == '1')
    when :wiki
      self.wiki = LastFM::Wiki.from_xml(node)
  end
end