Class: MetaSpotify::Album
Instance Attribute Summary collapse
-
#allmusic_id ⇒ Object
readonly
Returns the value of attribute allmusic_id.
-
#allmusic_uri ⇒ Object
readonly
Returns the value of attribute allmusic_uri.
-
#artists ⇒ Object
readonly
Returns the value of attribute artists.
-
#available_territories ⇒ Object
readonly
Returns the value of attribute available_territories.
-
#musicbrainz_id ⇒ Object
readonly
Returns the value of attribute musicbrainz_id.
-
#musicbrainz_uri ⇒ Object
readonly
Returns the value of attribute musicbrainz_uri.
-
#released ⇒ Object
readonly
Returns the value of attribute released.
-
#tracks ⇒ Object
readonly
Returns the value of attribute tracks.
-
#upc ⇒ Object
readonly
Returns the value of attribute upc.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #http_uri ⇒ Object
-
#initialize(hash) ⇒ Album
constructor
A new instance of Album.
- #is_available_in?(territory) ⇒ Boolean
- #is_not_available_in?(territory) ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize(hash) ⇒ Album
Returns a new instance of Album.
11 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/meta-spotify/album.rb', line 11 def initialize(hash) @name = hash['name'] @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 if hash.has_key? 'tracks' @tracks = [] if hash['tracks']['track'].is_a? Array hash['tracks']['track'].each { |a| @tracks << Track.new(a) } else @tracks << Track.new(hash['tracks']['track']) end end @released = hash['released'] if hash.has_key? 'released' @uri = hash['href'] if hash.has_key? 'href' if hash['id'].is_a? Array hash['id'].each do |id| case id['type'] when 'upc' then @upc = id['__content__'] when 'mbid' then @musicbrainz_id = id['__content__'] @musicbrainz_uri = id['href'] when 'amgid' then @allmusic_id = id['__content__'] @allmusic_uri = id['href'] end end end @available_territories = if hash.has_key?('availability') && !hash['availability']['territories'].nil? hash['availability']['territories'].split(/\s+/).map {|t| t.downcase } || [] else [] end end |
Instance Attribute Details
#allmusic_id ⇒ Object (readonly)
Returns the value of attribute allmusic_id.
8 9 10 |
# File 'lib/meta-spotify/album.rb', line 8 def allmusic_id @allmusic_id end |
#allmusic_uri ⇒ Object (readonly)
Returns the value of attribute allmusic_uri.
8 9 10 |
# File 'lib/meta-spotify/album.rb', line 8 def allmusic_uri @allmusic_uri end |
#artists ⇒ Object (readonly)
Returns the value of attribute artists.
8 9 10 |
# File 'lib/meta-spotify/album.rb', line 8 def artists @artists end |
#available_territories ⇒ Object (readonly)
Returns the value of attribute available_territories.
8 9 10 |
# File 'lib/meta-spotify/album.rb', line 8 def available_territories @available_territories end |
#musicbrainz_id ⇒ Object (readonly)
Returns the value of attribute musicbrainz_id.
8 9 10 |
# File 'lib/meta-spotify/album.rb', line 8 def musicbrainz_id @musicbrainz_id end |
#musicbrainz_uri ⇒ Object (readonly)
Returns the value of attribute musicbrainz_uri.
8 9 10 |
# File 'lib/meta-spotify/album.rb', line 8 def musicbrainz_uri @musicbrainz_uri end |
#released ⇒ Object (readonly)
Returns the value of attribute released.
8 9 10 |
# File 'lib/meta-spotify/album.rb', line 8 def released @released end |
#tracks ⇒ Object (readonly)
Returns the value of attribute tracks.
8 9 10 |
# File 'lib/meta-spotify/album.rb', line 8 def tracks @tracks end |
#upc ⇒ Object (readonly)
Returns the value of attribute upc.
8 9 10 |
# File 'lib/meta-spotify/album.rb', line 8 def upc @upc end |
Class Method Details
.uri_regex ⇒ Object
4 5 6 |
# File 'lib/meta-spotify/album.rb', line 4 def self.uri_regex /^spotify:album:([A-Za-z0-9]+)$/ end |
Instance Method Details
#http_uri ⇒ Object
64 65 66 |
# File 'lib/meta-spotify/album.rb', line 64 def http_uri "http://open.spotify.com/album/#{spotify_id}" end |
#is_available_in?(territory) ⇒ Boolean
56 57 58 |
# File 'lib/meta-spotify/album.rb', line 56 def is_available_in?(territory) (@available_territories.include?('worldwide') || @available_territories.include?(territory.downcase)) end |
#is_not_available_in?(territory) ⇒ Boolean
60 61 62 |
# File 'lib/meta-spotify/album.rb', line 60 def is_not_available_in?(territory) !is_available_in?(territory) end |