Class: Drum::Album

Inherits:
Struct show all
Defined in:
lib/drum/model/album.rb

Overview

A album, i.e. a composition of tracks by an artist.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAlbum

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

#applemusicoptional, AlbumAppleMusic

Returns Apple Music-specific metadata.

Returns:



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_idsArray<String>

Returns The artist ids of the album.

Returns:



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

#idString

Returns The (internal) id of the album.

Returns:

  • (String)

    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

#nameString

Returns The name of the album.

Returns:

  • (String)

    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

#spotifyoptional, AlbumSpotify

Returns Spotify-specific metadata.

Returns:



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.

Parameters:

Returns:

  • (Album)

    The parsed album



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

#serializeHash<String, Object>

Serializes the album to a nested Hash that uses string keys.

Returns:



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