Class: Drum::User
Overview
A user.
Instance Attribute Summary collapse
-
#display_name ⇒ optional, String
The general formatted name of the user.
-
#id ⇒ String
The (internal) id of the user.
-
#spotify ⇒ optional, UserSpotify
Spotify-specific metadata.
Class Method Summary collapse
-
.deserialize(h) ⇒ User
Parses a user from a nested Hash that uses string keys.
Instance Method Summary collapse
-
#serialize ⇒ Hash<String, Object>
Serializes the user to a nested Hash that uses string keys.
Instance Attribute Details
#display_name ⇒ optional, String
Returns 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 |
#id ⇒ String
Returns 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 |
#spotify ⇒ optional, UserSpotify
Returns 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.
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 |