Class: SpotifyWeb::Album

Inherits:
Resource show all
Defined in:
lib/spotify_web/album.rb

Overview

Represents an album on Spotify

Constant Summary

Constants inherited from Resource

Resource::BASE62_CHARS

Instance Attribute Summary collapse

Attributes inherited from Resource

#gid, #id, #uri, #uri_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, attribute, #attributes=, #hash, #initialize, #load, #load_metadata, #loaded?, #metadata=, #metadata_uri, #pretty_print, #pretty_print_instance_variables

Methods included from Assertions

#assert_valid_keys, #assert_valid_values

Constructor Details

This class inherits a constructor from SpotifyWeb::Resource

Instance Attribute Details

#artistString (readonly)

Info about the artist

Returns:

  • (String)

34
35
36
# File 'lib/spotify_web/album.rb', line 34

attribute :artist do |artist|
  Artist.new(client, artist[0].to_hash)
end

#labelString (readonly)

The label that released the album

Returns:

  • (String)

40
# File 'lib/spotify_web/album.rb', line 40

attribute :label

#popularityFixnum (readonly)

The relative popularity of this artist on Spotify

Returns:

  • (Fixnum)

50
# File 'lib/spotify_web/album.rb', line 50

attribute :popularity

#published_onDate (readonly)

The date the album was published on

Returns:

  • (Date)

44
45
46
# File 'lib/spotify_web/album.rb', line 44

attribute :published_on, :date do |date|
  Date.new(date.year, date.month || 1, date.day || 1)
end

#restrictionsArray<SpotifyWeb::Restriction> (readonly)

The countries for which this album is permitted to be played

Returns:


65
66
67
# File 'lib/spotify_web/album.rb', line 65

attribute :restrictions, :restriction do |restrictions|
  restrictions.map {|restriction| Restriction.new(client, restriction.to_hash)}
end

#songsArray<SpotifyWeb::Song> (readonly)

The songs recorded on this album

Returns:


54
55
56
57
58
59
60
61
# File 'lib/spotify_web/album.rb', line 54

attribute :songs, :disc do |discs|
  songs = []
  discs.each do |disc|
    disc_songs = disc.track.map {|track| Song.new(client, track.to_hash)}
    songs.concat(disc_songs)
  end
  ResourceCollection.new(client, songs)
end

#titleString (readonly)

The title of the album

Returns:

  • (String)

30
# File 'lib/spotify_web/album.rb', line 30

attribute :title, :name

Class Method Details

.from_search_result(client, attributes) ⇒ Object

:nodoc:


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

def self.from_search_result(client, attributes) #:nodoc:
  attributes = attributes.merge(
    'artist' => [{
      :id => attributes['artist_id'],
      :name => attributes['artist_name']
    }],
    'restriction' => [attributes['restrictions']['restriction']].flatten.map do |restriction|
      {
        :countries_allowed => restriction['allowed'] && restriction['allowed'].split(',').join,
        :countries_forbidden => restriction['forbidden'] && restriction['forbidden'].split(',').join
      }
    end
  )

  super
end

Instance Method Details

#available?Boolean

Whether this album is available to the user

Returns:

  • (Boolean)

71
72
73
# File 'lib/spotify_web/album.rb', line 71

def available?
  restrictions.all? {|restriction| restriction.permitted?}
end