Class: Drum::User

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

Overview

A user.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#display_nameoptional, String

Returns The general formatted name of the user.

Returns:

  • (optional, String)

    The general formatted name of the user



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/user.rb', line 10

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

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

#idString

Returns The (internal) id of the user.

Returns:

  • (String)

    The (internal) id of the user



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/user.rb', line 10

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

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

#spotifyoptional, UserSpotify

Returns Spotify-specific metadata.

Returns:

  • (optional, UserSpotify)

    Spotify-specific metadata



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/user.rb', line 10

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

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

Class Method Details

.deserialize(h) ⇒ User

Parses a user from a nested Hash that uses string keys.

Parameters:

Returns:

  • (User)

    The parsed user



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

def self.deserialize(h)
  User.new(
    id: h['id'],
    display_name: h['display_name'],
    spotify: h['spotify'].try { |s| UserSpotify.deserialize(s) }
  )
end

Instance Method Details

#serializeHash<String, Object>

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

Returns:



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

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