lib/meta-spotify/album.rb in meta-spotify-0.1.1 vs lib/meta-spotify/album.rb in meta-spotify-0.1.2

- old
+ new

@@ -1,11 +1,12 @@ module MetaSpotify class Album < MetaSpotify::Base URI_REGEX = /^spotify:album:[A-Za-z0-9]+$/ - attr_reader :released, :artists, :available_territories, :tracks + attr_reader :released, :artists, :available_territories, :tracks, :upc, + :musicbrainz_id, :musicbrainz_uri, :allmusic_id, :allmusic_uri def initialize(hash) @name = hash['name'] if hash.has_key? 'artist' @artists = [] @@ -23,22 +24,38 @@ @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.attributes['type'] + when 'upc' then + @upc = id + when 'mbid' then + @musicbrainz_id = id + @musicbrainz_uri = id.attributes['href'] + when 'amgid' then + @allmusic_id = id + @allmusic_uri = id.attributes['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 def is_available_in?(territory) - return @available_territories.include?('worldwide') || @available_territories.include?(territory.downcase) + (@available_territories.include?('worldwide') || @available_territories.include?(territory.downcase)) end def is_not_available_in?(territory) - return !is_available_in?(territory) + !is_available_in?(territory) end - end end \ No newline at end of file