Class: Drum::TrackSpotify

Inherits:
Struct
  • Object
show all
Defined in:
lib/drum/model/track.rb

Overview

Spotify-specific metadata about the track.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idString

Returns The id of the track on Spotify.

Returns:

  • (String)

    The id of the track on Spotify



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/drum/model/track.rb', line 97

TrackSpotify = Struct.new(
  :id,
  keyword_init: true
) do
  # Parses spotify metadata from a Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [TrackSpotify] The parsed metadata
  def self.deserialize(h)
    TrackSpotify.new(
      id: h['id']
    )
  end

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

Class Method Details

.deserialize(h) ⇒ TrackSpotify

Parses spotify metadata from a Hash that uses string keys.

Parameters:

Returns:



105
106
107
108
109
# File 'lib/drum/model/track.rb', line 105

def self.deserialize(h)
  TrackSpotify.new(
    id: h['id']
  )
end

Instance Method Details

#serializeHash<String, Object>

Serializes the metadata to a Hash that uses string keys.

Returns:



114
115
116
117
118
# File 'lib/drum/model/track.rb', line 114

def serialize
  {
    'id' => self.id
  }.compact
end