Class: MetaSpotify::Track

Inherits:
Base
  • Object
show all
Defined in:
lib/meta-spotify/track.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#name, #popularity, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

lookup, search, #spotify_id

Constructor Details

#initialize(hash) ⇒ Track



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/meta-spotify/track.rb', line 12

def initialize(hash)
  @name = hash['name']
  @uri = hash['href'] if hash.has_key? 'href'
  @popularity = hash['popularity'].to_f if hash.has_key? 'popularity'

  if hash.has_key? 'artist'
    @artists = []
    if hash['artist'].is_a? Array
      hash['artist'].each { |a| @artists << Artist.new(a) }
    else
      @artists << Artist.new(hash['artist'])
    end
  end

  @album = Album.new(hash['album']) if hash.has_key? 'album'
  @track_number = hash['track_number'].to_i if hash.has_key? 'track_number'
  @length = hash['length'].to_f if hash.has_key? 'length'

  case hash['id']
  when Hash
    node_to_id hash['id']
  when Array
    hash['id'].each do |id|
      node_to_id id
    end
  end
end

Instance Attribute Details

#albumObject (readonly)

Returns the value of attribute album.



8
9
10
# File 'lib/meta-spotify/track.rb', line 8

def album
  @album
end

#allmusic_idObject (readonly)

Returns the value of attribute allmusic_id.



8
9
10
# File 'lib/meta-spotify/track.rb', line 8

def allmusic_id
  @allmusic_id
end

#allmusic_uriObject (readonly)

Returns the value of attribute allmusic_uri.



8
9
10
# File 'lib/meta-spotify/track.rb', line 8

def allmusic_uri
  @allmusic_uri
end

#artistsObject (readonly)

Returns the value of attribute artists.



8
9
10
# File 'lib/meta-spotify/track.rb', line 8

def artists
  @artists
end

#isrc_idObject (readonly)

Returns the value of attribute isrc_id.



8
9
10
# File 'lib/meta-spotify/track.rb', line 8

def isrc_id
  @isrc_id
end

#lengthObject (readonly)

Returns the value of attribute length.



8
9
10
# File 'lib/meta-spotify/track.rb', line 8

def length
  @length
end

#musicbrainz_idObject (readonly)

Returns the value of attribute musicbrainz_id.



8
9
10
# File 'lib/meta-spotify/track.rb', line 8

def musicbrainz_id
  @musicbrainz_id
end

#musicbrainz_uriObject (readonly)

Returns the value of attribute musicbrainz_uri.



8
9
10
# File 'lib/meta-spotify/track.rb', line 8

def musicbrainz_uri
  @musicbrainz_uri
end

#track_numberObject (readonly)

Returns the value of attribute track_number.



8
9
10
# File 'lib/meta-spotify/track.rb', line 8

def track_number
  @track_number
end

Class Method Details

.uri_regexObject



4
5
6
# File 'lib/meta-spotify/track.rb', line 4

def self.uri_regex
  /^spotify:track:([A-Za-z0-9]+)$/
end

Instance Method Details

#http_uriObject



40
41
42
# File 'lib/meta-spotify/track.rb', line 40

def http_uri
  "http://open.spotify.com/track/#{spotify_id}"
end