Class: Drum::Track

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

Overview

A track/song.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTrack

Returns a new instance of Track.



42
43
44
45
46
47
# File 'lib/drum/model/track.rb', line 42

def initialize(*)
  super
  self.artist_ids ||= []
  self.composer_ids ||= []
  self.genres ||= []
end

Instance Attribute Details

#added_atoptional, DateTime

Returns The date/time the this track was added to the playlist.

Returns:

  • (optional, DateTime)

    The date/time the this track was added to the playlist



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drum/model/track.rb', line 33

Track = Struct.new(
  :name,
  :artist_ids, :composer_ids, :album_id,
  :genres,
  :duration_ms, :explicit,
  :released_at, :added_at, :added_by,
  :isrc, :spotify, :applemusic,
  keyword_init: true
) do
  def initialize(*)
    super
    self.artist_ids ||= []
    self.composer_ids ||= []
    self.genres ||= []
  end

  # Parses a track from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Track] The parsed track
  def self.deserialize(h)
    Track.new(
      name: h['name'],
      artist_ids: h['artist_ids'],
      composer_ids: h['composer_ids'],
      genres: h['genres'],
      album_id: h['album_id'],
      duration_ms: h['duration_ms'],
      explicit: h['explicit'],
      released_at: h['released_at'].try { |d| DateTime.parse(d) },
      added_at: h['added_at'].try { |d| DateTime.parse(d) },
      added_by: h['added_by'],
      isrc: h['isrc'],
      spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
      applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
    )
  end

  # Serializes the track to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'name' => self.name,
      'artist_ids' => self.artist_ids,
      'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
      'genres' => (self.genres unless self.genres.empty?),
      'album_id' => self.album_id,
      'duration_ms' => self.duration_ms,
      'explicit' => self.explicit,
      'released_at' => self.released_at&.iso8601,
      'added_at' => self.added_at&.iso8601,
      'added_by' => self.added_by,
      'isrc' => self.isrc,
      'spotify' => self.spotify&.serialize,
      'applemusic' => self.applemusic&.serialize
    }.compact
  end
end

#added_byoptional, String

Returns The user id of the user who added this track to the playlist.

Returns:

  • (optional, String)

    The user id of the user who added this track to the playlist



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drum/model/track.rb', line 33

Track = Struct.new(
  :name,
  :artist_ids, :composer_ids, :album_id,
  :genres,
  :duration_ms, :explicit,
  :released_at, :added_at, :added_by,
  :isrc, :spotify, :applemusic,
  keyword_init: true
) do
  def initialize(*)
    super
    self.artist_ids ||= []
    self.composer_ids ||= []
    self.genres ||= []
  end

  # Parses a track from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Track] The parsed track
  def self.deserialize(h)
    Track.new(
      name: h['name'],
      artist_ids: h['artist_ids'],
      composer_ids: h['composer_ids'],
      genres: h['genres'],
      album_id: h['album_id'],
      duration_ms: h['duration_ms'],
      explicit: h['explicit'],
      released_at: h['released_at'].try { |d| DateTime.parse(d) },
      added_at: h['added_at'].try { |d| DateTime.parse(d) },
      added_by: h['added_by'],
      isrc: h['isrc'],
      spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
      applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
    )
  end

  # Serializes the track to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'name' => self.name,
      'artist_ids' => self.artist_ids,
      'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
      'genres' => (self.genres unless self.genres.empty?),
      'album_id' => self.album_id,
      'duration_ms' => self.duration_ms,
      'explicit' => self.explicit,
      'released_at' => self.released_at&.iso8601,
      'added_at' => self.added_at&.iso8601,
      'added_by' => self.added_by,
      'isrc' => self.isrc,
      'spotify' => self.spotify&.serialize,
      'applemusic' => self.applemusic&.serialize
    }.compact
  end
end

#album_idoptional, String

Returns The (internal) album id.

Returns:

  • (optional, String)

    The (internal) album id



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drum/model/track.rb', line 33

Track = Struct.new(
  :name,
  :artist_ids, :composer_ids, :album_id,
  :genres,
  :duration_ms, :explicit,
  :released_at, :added_at, :added_by,
  :isrc, :spotify, :applemusic,
  keyword_init: true
) do
  def initialize(*)
    super
    self.artist_ids ||= []
    self.composer_ids ||= []
    self.genres ||= []
  end

  # Parses a track from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Track] The parsed track
  def self.deserialize(h)
    Track.new(
      name: h['name'],
      artist_ids: h['artist_ids'],
      composer_ids: h['composer_ids'],
      genres: h['genres'],
      album_id: h['album_id'],
      duration_ms: h['duration_ms'],
      explicit: h['explicit'],
      released_at: h['released_at'].try { |d| DateTime.parse(d) },
      added_at: h['added_at'].try { |d| DateTime.parse(d) },
      added_by: h['added_by'],
      isrc: h['isrc'],
      spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
      applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
    )
  end

  # Serializes the track to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'name' => self.name,
      'artist_ids' => self.artist_ids,
      'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
      'genres' => (self.genres unless self.genres.empty?),
      'album_id' => self.album_id,
      'duration_ms' => self.duration_ms,
      'explicit' => self.explicit,
      'released_at' => self.released_at&.iso8601,
      'added_at' => self.added_at&.iso8601,
      'added_by' => self.added_by,
      'isrc' => self.isrc,
      'spotify' => self.spotify&.serialize,
      'applemusic' => self.applemusic&.serialize
    }.compact
  end
end

#applemusicoptional, TrackAppleMusic

Returns Apple Music-specific metadata.

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drum/model/track.rb', line 33

Track = Struct.new(
  :name,
  :artist_ids, :composer_ids, :album_id,
  :genres,
  :duration_ms, :explicit,
  :released_at, :added_at, :added_by,
  :isrc, :spotify, :applemusic,
  keyword_init: true
) do
  def initialize(*)
    super
    self.artist_ids ||= []
    self.composer_ids ||= []
    self.genres ||= []
  end

  # Parses a track from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Track] The parsed track
  def self.deserialize(h)
    Track.new(
      name: h['name'],
      artist_ids: h['artist_ids'],
      composer_ids: h['composer_ids'],
      genres: h['genres'],
      album_id: h['album_id'],
      duration_ms: h['duration_ms'],
      explicit: h['explicit'],
      released_at: h['released_at'].try { |d| DateTime.parse(d) },
      added_at: h['added_at'].try { |d| DateTime.parse(d) },
      added_by: h['added_by'],
      isrc: h['isrc'],
      spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
      applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
    )
  end

  # Serializes the track to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'name' => self.name,
      'artist_ids' => self.artist_ids,
      'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
      'genres' => (self.genres unless self.genres.empty?),
      'album_id' => self.album_id,
      'duration_ms' => self.duration_ms,
      'explicit' => self.explicit,
      'released_at' => self.released_at&.iso8601,
      'added_at' => self.added_at&.iso8601,
      'added_by' => self.added_by,
      'isrc' => self.isrc,
      'spotify' => self.spotify&.serialize,
      'applemusic' => self.applemusic&.serialize
    }.compact
  end
end

#artist_idsArray<String>

Returns The (internal) artist ids.

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drum/model/track.rb', line 33

Track = Struct.new(
  :name,
  :artist_ids, :composer_ids, :album_id,
  :genres,
  :duration_ms, :explicit,
  :released_at, :added_at, :added_by,
  :isrc, :spotify, :applemusic,
  keyword_init: true
) do
  def initialize(*)
    super
    self.artist_ids ||= []
    self.composer_ids ||= []
    self.genres ||= []
  end

  # Parses a track from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Track] The parsed track
  def self.deserialize(h)
    Track.new(
      name: h['name'],
      artist_ids: h['artist_ids'],
      composer_ids: h['composer_ids'],
      genres: h['genres'],
      album_id: h['album_id'],
      duration_ms: h['duration_ms'],
      explicit: h['explicit'],
      released_at: h['released_at'].try { |d| DateTime.parse(d) },
      added_at: h['added_at'].try { |d| DateTime.parse(d) },
      added_by: h['added_by'],
      isrc: h['isrc'],
      spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
      applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
    )
  end

  # Serializes the track to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'name' => self.name,
      'artist_ids' => self.artist_ids,
      'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
      'genres' => (self.genres unless self.genres.empty?),
      'album_id' => self.album_id,
      'duration_ms' => self.duration_ms,
      'explicit' => self.explicit,
      'released_at' => self.released_at&.iso8601,
      'added_at' => self.added_at&.iso8601,
      'added_by' => self.added_by,
      'isrc' => self.isrc,
      'spotify' => self.spotify&.serialize,
      'applemusic' => self.applemusic&.serialize
    }.compact
  end
end

#composer_idsoptional, Array<String>

Returns The (internal) composer ids.

Returns:

  • (optional, Array<String>)

    The (internal) composer ids



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drum/model/track.rb', line 33

Track = Struct.new(
  :name,
  :artist_ids, :composer_ids, :album_id,
  :genres,
  :duration_ms, :explicit,
  :released_at, :added_at, :added_by,
  :isrc, :spotify, :applemusic,
  keyword_init: true
) do
  def initialize(*)
    super
    self.artist_ids ||= []
    self.composer_ids ||= []
    self.genres ||= []
  end

  # Parses a track from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Track] The parsed track
  def self.deserialize(h)
    Track.new(
      name: h['name'],
      artist_ids: h['artist_ids'],
      composer_ids: h['composer_ids'],
      genres: h['genres'],
      album_id: h['album_id'],
      duration_ms: h['duration_ms'],
      explicit: h['explicit'],
      released_at: h['released_at'].try { |d| DateTime.parse(d) },
      added_at: h['added_at'].try { |d| DateTime.parse(d) },
      added_by: h['added_by'],
      isrc: h['isrc'],
      spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
      applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
    )
  end

  # Serializes the track to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'name' => self.name,
      'artist_ids' => self.artist_ids,
      'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
      'genres' => (self.genres unless self.genres.empty?),
      'album_id' => self.album_id,
      'duration_ms' => self.duration_ms,
      'explicit' => self.explicit,
      'released_at' => self.released_at&.iso8601,
      'added_at' => self.added_at&.iso8601,
      'added_by' => self.added_by,
      'isrc' => self.isrc,
      'spotify' => self.spotify&.serialize,
      'applemusic' => self.applemusic&.serialize
    }.compact
  end
end

#duration_msoptional, Float

Returns The duration of the track in milliseconds.

Returns:

  • (optional, Float)

    The duration of the track in milliseconds



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drum/model/track.rb', line 33

Track = Struct.new(
  :name,
  :artist_ids, :composer_ids, :album_id,
  :genres,
  :duration_ms, :explicit,
  :released_at, :added_at, :added_by,
  :isrc, :spotify, :applemusic,
  keyword_init: true
) do
  def initialize(*)
    super
    self.artist_ids ||= []
    self.composer_ids ||= []
    self.genres ||= []
  end

  # Parses a track from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Track] The parsed track
  def self.deserialize(h)
    Track.new(
      name: h['name'],
      artist_ids: h['artist_ids'],
      composer_ids: h['composer_ids'],
      genres: h['genres'],
      album_id: h['album_id'],
      duration_ms: h['duration_ms'],
      explicit: h['explicit'],
      released_at: h['released_at'].try { |d| DateTime.parse(d) },
      added_at: h['added_at'].try { |d| DateTime.parse(d) },
      added_by: h['added_by'],
      isrc: h['isrc'],
      spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
      applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
    )
  end

  # Serializes the track to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'name' => self.name,
      'artist_ids' => self.artist_ids,
      'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
      'genres' => (self.genres unless self.genres.empty?),
      'album_id' => self.album_id,
      'duration_ms' => self.duration_ms,
      'explicit' => self.explicit,
      'released_at' => self.released_at&.iso8601,
      'added_at' => self.added_at&.iso8601,
      'added_by' => self.added_by,
      'isrc' => self.isrc,
      'spotify' => self.spotify&.serialize,
      'applemusic' => self.applemusic&.serialize
    }.compact
  end
end

#explicitoptional, Boolean

Returns Whether the track is explicit.

Returns:

  • (optional, Boolean)

    Whether the track is explicit



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drum/model/track.rb', line 33

Track = Struct.new(
  :name,
  :artist_ids, :composer_ids, :album_id,
  :genres,
  :duration_ms, :explicit,
  :released_at, :added_at, :added_by,
  :isrc, :spotify, :applemusic,
  keyword_init: true
) do
  def initialize(*)
    super
    self.artist_ids ||= []
    self.composer_ids ||= []
    self.genres ||= []
  end

  # Parses a track from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Track] The parsed track
  def self.deserialize(h)
    Track.new(
      name: h['name'],
      artist_ids: h['artist_ids'],
      composer_ids: h['composer_ids'],
      genres: h['genres'],
      album_id: h['album_id'],
      duration_ms: h['duration_ms'],
      explicit: h['explicit'],
      released_at: h['released_at'].try { |d| DateTime.parse(d) },
      added_at: h['added_at'].try { |d| DateTime.parse(d) },
      added_by: h['added_by'],
      isrc: h['isrc'],
      spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
      applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
    )
  end

  # Serializes the track to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'name' => self.name,
      'artist_ids' => self.artist_ids,
      'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
      'genres' => (self.genres unless self.genres.empty?),
      'album_id' => self.album_id,
      'duration_ms' => self.duration_ms,
      'explicit' => self.explicit,
      'released_at' => self.released_at&.iso8601,
      'added_at' => self.added_at&.iso8601,
      'added_by' => self.added_by,
      'isrc' => self.isrc,
      'spotify' => self.spotify&.serialize,
      'applemusic' => self.applemusic&.serialize
    }.compact
  end
end

#genresoptional, Array<String>

Returns The track’s genre names.

Returns:

  • (optional, Array<String>)

    The track’s genre names



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drum/model/track.rb', line 33

Track = Struct.new(
  :name,
  :artist_ids, :composer_ids, :album_id,
  :genres,
  :duration_ms, :explicit,
  :released_at, :added_at, :added_by,
  :isrc, :spotify, :applemusic,
  keyword_init: true
) do
  def initialize(*)
    super
    self.artist_ids ||= []
    self.composer_ids ||= []
    self.genres ||= []
  end

  # Parses a track from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Track] The parsed track
  def self.deserialize(h)
    Track.new(
      name: h['name'],
      artist_ids: h['artist_ids'],
      composer_ids: h['composer_ids'],
      genres: h['genres'],
      album_id: h['album_id'],
      duration_ms: h['duration_ms'],
      explicit: h['explicit'],
      released_at: h['released_at'].try { |d| DateTime.parse(d) },
      added_at: h['added_at'].try { |d| DateTime.parse(d) },
      added_by: h['added_by'],
      isrc: h['isrc'],
      spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
      applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
    )
  end

  # Serializes the track to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'name' => self.name,
      'artist_ids' => self.artist_ids,
      'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
      'genres' => (self.genres unless self.genres.empty?),
      'album_id' => self.album_id,
      'duration_ms' => self.duration_ms,
      'explicit' => self.explicit,
      'released_at' => self.released_at&.iso8601,
      'added_at' => self.added_at&.iso8601,
      'added_by' => self.added_by,
      'isrc' => self.isrc,
      'spotify' => self.spotify&.serialize,
      'applemusic' => self.applemusic&.serialize
    }.compact
  end
end

#isrcoptional, String

Returns The International Standard Recording Code of this track.

Returns:

  • (optional, String)

    The International Standard Recording Code of this track



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drum/model/track.rb', line 33

Track = Struct.new(
  :name,
  :artist_ids, :composer_ids, :album_id,
  :genres,
  :duration_ms, :explicit,
  :released_at, :added_at, :added_by,
  :isrc, :spotify, :applemusic,
  keyword_init: true
) do
  def initialize(*)
    super
    self.artist_ids ||= []
    self.composer_ids ||= []
    self.genres ||= []
  end

  # Parses a track from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Track] The parsed track
  def self.deserialize(h)
    Track.new(
      name: h['name'],
      artist_ids: h['artist_ids'],
      composer_ids: h['composer_ids'],
      genres: h['genres'],
      album_id: h['album_id'],
      duration_ms: h['duration_ms'],
      explicit: h['explicit'],
      released_at: h['released_at'].try { |d| DateTime.parse(d) },
      added_at: h['added_at'].try { |d| DateTime.parse(d) },
      added_by: h['added_by'],
      isrc: h['isrc'],
      spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
      applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
    )
  end

  # Serializes the track to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'name' => self.name,
      'artist_ids' => self.artist_ids,
      'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
      'genres' => (self.genres unless self.genres.empty?),
      'album_id' => self.album_id,
      'duration_ms' => self.duration_ms,
      'explicit' => self.explicit,
      'released_at' => self.released_at&.iso8601,
      'added_at' => self.added_at&.iso8601,
      'added_by' => self.added_by,
      'isrc' => self.isrc,
      'spotify' => self.spotify&.serialize,
      'applemusic' => self.applemusic&.serialize
    }.compact
  end
end

#nameString

Returns The name of the track.

Returns:

  • (String)

    The name of the track



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drum/model/track.rb', line 33

Track = Struct.new(
  :name,
  :artist_ids, :composer_ids, :album_id,
  :genres,
  :duration_ms, :explicit,
  :released_at, :added_at, :added_by,
  :isrc, :spotify, :applemusic,
  keyword_init: true
) do
  def initialize(*)
    super
    self.artist_ids ||= []
    self.composer_ids ||= []
    self.genres ||= []
  end

  # Parses a track from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Track] The parsed track
  def self.deserialize(h)
    Track.new(
      name: h['name'],
      artist_ids: h['artist_ids'],
      composer_ids: h['composer_ids'],
      genres: h['genres'],
      album_id: h['album_id'],
      duration_ms: h['duration_ms'],
      explicit: h['explicit'],
      released_at: h['released_at'].try { |d| DateTime.parse(d) },
      added_at: h['added_at'].try { |d| DateTime.parse(d) },
      added_by: h['added_by'],
      isrc: h['isrc'],
      spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
      applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
    )
  end

  # Serializes the track to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'name' => self.name,
      'artist_ids' => self.artist_ids,
      'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
      'genres' => (self.genres unless self.genres.empty?),
      'album_id' => self.album_id,
      'duration_ms' => self.duration_ms,
      'explicit' => self.explicit,
      'released_at' => self.released_at&.iso8601,
      'added_at' => self.added_at&.iso8601,
      'added_by' => self.added_by,
      'isrc' => self.isrc,
      'spotify' => self.spotify&.serialize,
      'applemusic' => self.applemusic&.serialize
    }.compact
  end
end

#released_atoptional, DateTime

Returns The date/time the this track was released.

Returns:

  • (optional, DateTime)

    The date/time the this track was released



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drum/model/track.rb', line 33

Track = Struct.new(
  :name,
  :artist_ids, :composer_ids, :album_id,
  :genres,
  :duration_ms, :explicit,
  :released_at, :added_at, :added_by,
  :isrc, :spotify, :applemusic,
  keyword_init: true
) do
  def initialize(*)
    super
    self.artist_ids ||= []
    self.composer_ids ||= []
    self.genres ||= []
  end

  # Parses a track from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Track] The parsed track
  def self.deserialize(h)
    Track.new(
      name: h['name'],
      artist_ids: h['artist_ids'],
      composer_ids: h['composer_ids'],
      genres: h['genres'],
      album_id: h['album_id'],
      duration_ms: h['duration_ms'],
      explicit: h['explicit'],
      released_at: h['released_at'].try { |d| DateTime.parse(d) },
      added_at: h['added_at'].try { |d| DateTime.parse(d) },
      added_by: h['added_by'],
      isrc: h['isrc'],
      spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
      applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
    )
  end

  # Serializes the track to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'name' => self.name,
      'artist_ids' => self.artist_ids,
      'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
      'genres' => (self.genres unless self.genres.empty?),
      'album_id' => self.album_id,
      'duration_ms' => self.duration_ms,
      'explicit' => self.explicit,
      'released_at' => self.released_at&.iso8601,
      'added_at' => self.added_at&.iso8601,
      'added_by' => self.added_by,
      'isrc' => self.isrc,
      'spotify' => self.spotify&.serialize,
      'applemusic' => self.applemusic&.serialize
    }.compact
  end
end

#spotifyoptional, TrackSpotify

Returns Spotify-specific metadata.

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drum/model/track.rb', line 33

Track = Struct.new(
  :name,
  :artist_ids, :composer_ids, :album_id,
  :genres,
  :duration_ms, :explicit,
  :released_at, :added_at, :added_by,
  :isrc, :spotify, :applemusic,
  keyword_init: true
) do
  def initialize(*)
    super
    self.artist_ids ||= []
    self.composer_ids ||= []
    self.genres ||= []
  end

  # Parses a track from a nested Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [Track] The parsed track
  def self.deserialize(h)
    Track.new(
      name: h['name'],
      artist_ids: h['artist_ids'],
      composer_ids: h['composer_ids'],
      genres: h['genres'],
      album_id: h['album_id'],
      duration_ms: h['duration_ms'],
      explicit: h['explicit'],
      released_at: h['released_at'].try { |d| DateTime.parse(d) },
      added_at: h['added_at'].try { |d| DateTime.parse(d) },
      added_by: h['added_by'],
      isrc: h['isrc'],
      spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
      applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
    )
  end

  # Serializes the track to a nested Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'name' => self.name,
      'artist_ids' => self.artist_ids,
      'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
      'genres' => (self.genres unless self.genres.empty?),
      'album_id' => self.album_id,
      'duration_ms' => self.duration_ms,
      'explicit' => self.explicit,
      'released_at' => self.released_at&.iso8601,
      'added_at' => self.added_at&.iso8601,
      'added_by' => self.added_by,
      'isrc' => self.isrc,
      'spotify' => self.spotify&.serialize,
      'applemusic' => self.applemusic&.serialize
    }.compact
  end
end

Class Method Details

.deserialize(h) ⇒ Track

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

Parameters:

Returns:

  • (Track)

    The parsed track



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/drum/model/track.rb', line 53

def self.deserialize(h)
  Track.new(
    name: h['name'],
    artist_ids: h['artist_ids'],
    composer_ids: h['composer_ids'],
    genres: h['genres'],
    album_id: h['album_id'],
    duration_ms: h['duration_ms'],
    explicit: h['explicit'],
    released_at: h['released_at'].try { |d| DateTime.parse(d) },
    added_at: h['added_at'].try { |d| DateTime.parse(d) },
    added_by: h['added_by'],
    isrc: h['isrc'],
    spotify: h['spotify'].try { |s| TrackSpotify.deserialize(s) },
    applemusic: h['applemusic'].try { |s| TrackAppleMusic.deserialize(s) }
  )
end

Instance Method Details

#serializeHash<String, Object>

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

Returns:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/drum/model/track.rb', line 74

def serialize
  {
    'name' => self.name,
    'artist_ids' => self.artist_ids,
    'composer_ids' => (self.composer_ids unless self.composer_ids.empty?),
    'genres' => (self.genres unless self.genres.empty?),
    'album_id' => self.album_id,
    'duration_ms' => self.duration_ms,
    'explicit' => self.explicit,
    'released_at' => self.released_at&.iso8601,
    'added_at' => self.added_at&.iso8601,
    'added_by' => self.added_by,
    'isrc' => self.isrc,
    'spotify' => self.spotify&.serialize,
    'applemusic' => self.applemusic&.serialize
  }.compact
end