Class: Drum::Artist

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

Overview

An artist.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idString

Returns The (internal) id of the artist.

Returns:

  • (String)

    The (internal) id of the artist



10
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
# File 'lib/drum/model/artist.rb', line 10

Artist = Struct.new(
  :id,
  :name,
  :spotify,
  keyword_init: true
) do
  # Parses an artist from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Artist] The parsed artist
  def self.deserialize(h)
    Artist.new(
      id: h['id'],
      name: h['name'],
      spotify: h['spotify'].try { |s| ArtistSpotify.deserialize(s) }
    )
  end

  # Serializes the artist to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'id' => self.id,
      'name' => self.name,
      'spotify' => self.spotify&.serialize
    }.compact
  end
end

#nameoptional, String

Returns The displayed/formatted name of the artist.

Returns:

  • (optional, String)

    The displayed/formatted name of the artist



10
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
# File 'lib/drum/model/artist.rb', line 10

Artist = Struct.new(
  :id,
  :name,
  :spotify,
  keyword_init: true
) do
  # Parses an artist from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Artist] The parsed artist
  def self.deserialize(h)
    Artist.new(
      id: h['id'],
      name: h['name'],
      spotify: h['spotify'].try { |s| ArtistSpotify.deserialize(s) }
    )
  end

  # Serializes the artist to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'id' => self.id,
      'name' => self.name,
      'spotify' => self.spotify&.serialize
    }.compact
  end
end

#spotifyoptional, ArtistSpotify

Returns Spotify-specific metadata.

Returns:



10
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
# File 'lib/drum/model/artist.rb', line 10

Artist = Struct.new(
  :id,
  :name,
  :spotify,
  keyword_init: true
) do
  # Parses an artist from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Artist] The parsed artist
  def self.deserialize(h)
    Artist.new(
      id: h['id'],
      name: h['name'],
      spotify: h['spotify'].try { |s| ArtistSpotify.deserialize(s) }
    )
  end

  # Serializes the artist to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'id' => self.id,
      'name' => self.name,
      'spotify' => self.spotify&.serialize
    }.compact
  end
end

Class Method Details

.deserialize(h) ⇒ Artist

Parses an artist from a nested Hash that uses string keys.

Parameters:

Returns:

  • (Artist)

    The parsed artist



20
21
22
23
24
25
26
# File 'lib/drum/model/artist.rb', line 20

def self.deserialize(h)
  Artist.new(
    id: h['id'],
    name: h['name'],
    spotify: h['spotify'].try { |s| ArtistSpotify.deserialize(s) }
  )
end

Instance Method Details

#serializeHash<String, Object>

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

Returns:



31
32
33
34
35
36
37
# File 'lib/drum/model/artist.rb', line 31

def serialize
  {
    'id' => self.id,
    'name' => self.name,
    'spotify' => self.spotify&.serialize
  }.compact
end