Class: Drum::Album
Overview
A album, i.e. a composition of tracks by an artist.
Instance Attribute Summary collapse
-
#applemusic ⇒ optional, AlbumAppleMusic
Apple Music-specific metadata.
-
#artist_ids ⇒ Array<String>
The artist ids of the album.
-
#id ⇒ String
The (internal) id of the album.
-
#name ⇒ String
The name of the album.
-
#spotify ⇒ optional, AlbumSpotify
Spotify-specific metadata.
Class Method Summary collapse
-
.deserialize(h) ⇒ Album
Parses an album from a nested Hash that uses string keys.
Instance Method Summary collapse
-
#initialize ⇒ Album
constructor
A new instance of Album.
-
#serialize ⇒ Hash<String, Object>
Serializes the album to a nested Hash that uses string keys.
Constructor Details
#initialize ⇒ Album
Returns a new instance of Album.
21 22 23 24 |
# File 'lib/drum/model/album.rb', line 21 def initialize(*) super self.artist_ids ||= [] end |
Instance Attribute Details
#applemusic ⇒ optional, AlbumAppleMusic
Returns Apple Music-specific metadata.
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 |
# File 'lib/drum/model/album.rb', line 14 Album = Struct.new( :id, :name, :artist_ids, :spotify, :applemusic, keyword_init: true ) do def initialize(*) super self.artist_ids ||= [] end # Parses an album from a nested Hash that uses string keys. # # @param [Hash<String, Object>] h The Hash to be parsed # @return [Album] The parsed album def self.deserialize(h) Album.new( id: h['id'], name: h['name'], artist_ids: h['artist_ids'], spotify: h['spotify'].try { |s| AlbumSpotify.deserialize(s) }, applemusic: h['applemusic'].try { |s| AlbumAppleMusic.deserialize(s) } ) end # Serializes the album to a nested Hash that uses string keys. # # @return [Hash<String, Object>] The serialized representation def serialize { 'id' => self.id, 'name' => self.name, 'artist_ids' => self.artist_ids, 'spotify' => self.spotify&.serialize, 'applemusic' => self.applemusic&.serialize }.compact end end |
#artist_ids ⇒ Array<String>
Returns The artist ids of the album.
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 |
# File 'lib/drum/model/album.rb', line 14 Album = Struct.new( :id, :name, :artist_ids, :spotify, :applemusic, keyword_init: true ) do def initialize(*) super self.artist_ids ||= [] end # Parses an album from a nested Hash that uses string keys. # # @param [Hash<String, Object>] h The Hash to be parsed # @return [Album] The parsed album def self.deserialize(h) Album.new( id: h['id'], name: h['name'], artist_ids: h['artist_ids'], spotify: h['spotify'].try { |s| AlbumSpotify.deserialize(s) }, applemusic: h['applemusic'].try { |s| AlbumAppleMusic.deserialize(s) } ) end # Serializes the album to a nested Hash that uses string keys. # # @return [Hash<String, Object>] The serialized representation def serialize { 'id' => self.id, 'name' => self.name, 'artist_ids' => self.artist_ids, 'spotify' => self.spotify&.serialize, 'applemusic' => self.applemusic&.serialize }.compact end end |
#id ⇒ String
Returns The (internal) id of the album.
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 |
# File 'lib/drum/model/album.rb', line 14 Album = Struct.new( :id, :name, :artist_ids, :spotify, :applemusic, keyword_init: true ) do def initialize(*) super self.artist_ids ||= [] end # Parses an album from a nested Hash that uses string keys. # # @param [Hash<String, Object>] h The Hash to be parsed # @return [Album] The parsed album def self.deserialize(h) Album.new( id: h['id'], name: h['name'], artist_ids: h['artist_ids'], spotify: h['spotify'].try { |s| AlbumSpotify.deserialize(s) }, applemusic: h['applemusic'].try { |s| AlbumAppleMusic.deserialize(s) } ) end # Serializes the album to a nested Hash that uses string keys. # # @return [Hash<String, Object>] The serialized representation def serialize { 'id' => self.id, 'name' => self.name, 'artist_ids' => self.artist_ids, 'spotify' => self.spotify&.serialize, 'applemusic' => self.applemusic&.serialize }.compact end end |
#name ⇒ String
Returns The name of the album.
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 |
# File 'lib/drum/model/album.rb', line 14 Album = Struct.new( :id, :name, :artist_ids, :spotify, :applemusic, keyword_init: true ) do def initialize(*) super self.artist_ids ||= [] end # Parses an album from a nested Hash that uses string keys. # # @param [Hash<String, Object>] h The Hash to be parsed # @return [Album] The parsed album def self.deserialize(h) Album.new( id: h['id'], name: h['name'], artist_ids: h['artist_ids'], spotify: h['spotify'].try { |s| AlbumSpotify.deserialize(s) }, applemusic: h['applemusic'].try { |s| AlbumAppleMusic.deserialize(s) } ) end # Serializes the album to a nested Hash that uses string keys. # # @return [Hash<String, Object>] The serialized representation def serialize { 'id' => self.id, 'name' => self.name, 'artist_ids' => self.artist_ids, 'spotify' => self.spotify&.serialize, 'applemusic' => self.applemusic&.serialize }.compact end end |
#spotify ⇒ optional, AlbumSpotify
Returns Spotify-specific metadata.
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 |
# File 'lib/drum/model/album.rb', line 14 Album = Struct.new( :id, :name, :artist_ids, :spotify, :applemusic, keyword_init: true ) do def initialize(*) super self.artist_ids ||= [] end # Parses an album from a nested Hash that uses string keys. # # @param [Hash<String, Object>] h The Hash to be parsed # @return [Album] The parsed album def self.deserialize(h) Album.new( id: h['id'], name: h['name'], artist_ids: h['artist_ids'], spotify: h['spotify'].try { |s| AlbumSpotify.deserialize(s) }, applemusic: h['applemusic'].try { |s| AlbumAppleMusic.deserialize(s) } ) end # Serializes the album to a nested Hash that uses string keys. # # @return [Hash<String, Object>] The serialized representation def serialize { 'id' => self.id, 'name' => self.name, 'artist_ids' => self.artist_ids, 'spotify' => self.spotify&.serialize, 'applemusic' => self.applemusic&.serialize }.compact end end |
Class Method Details
.deserialize(h) ⇒ Album
Parses an album from a nested Hash that uses string keys.
30 31 32 33 34 35 36 37 38 |
# File 'lib/drum/model/album.rb', line 30 def self.deserialize(h) Album.new( id: h['id'], name: h['name'], artist_ids: h['artist_ids'], spotify: h['spotify'].try { |s| AlbumSpotify.deserialize(s) }, applemusic: h['applemusic'].try { |s| AlbumAppleMusic.deserialize(s) } ) end |
Instance Method Details
#serialize ⇒ Hash<String, Object>
Serializes the album to a nested Hash that uses string keys.
43 44 45 46 47 48 49 50 51 |
# File 'lib/drum/model/album.rb', line 43 def serialize { 'id' => self.id, 'name' => self.name, 'artist_ids' => self.artist_ids, 'spotify' => self.spotify&.serialize, 'applemusic' => self.applemusic&.serialize }.compact end |