Class: Drum::Track
Overview
A track/song.
Instance Attribute Summary collapse
- 
  
    
      #added_at  ⇒ optional, DateTime 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The date/time the this track was added to the playlist. 
- 
  
    
      #added_by  ⇒ optional, String 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The user id of the user who added this track to the playlist. 
- 
  
    
      #album_id  ⇒ optional, String 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The (internal) album id. 
- 
  
    
      #applemusic  ⇒ optional, TrackAppleMusic 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Apple Music-specific metadata. 
- 
  
    
      #artist_ids  ⇒ Array<String> 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The (internal) artist ids. 
- 
  
    
      #composer_ids  ⇒ optional, Array<String> 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The (internal) composer ids. 
- 
  
    
      #duration_ms  ⇒ optional, Float 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The duration of the track in milliseconds. 
- 
  
    
      #explicit  ⇒ optional, Boolean 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Whether the track is explicit. 
- 
  
    
      #genres  ⇒ optional, Array<String> 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The track's genre names. 
- 
  
    
      #isrc  ⇒ optional, String 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The International Standard Recording Code of this track. 
- 
  
    
      #name  ⇒ String 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The name of the track. 
- 
  
    
      #released_at  ⇒ optional, DateTime 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The date/time the this track was released. 
- 
  
    
      #spotify  ⇒ optional, TrackSpotify 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Spotify-specific metadata. 
Class Method Summary collapse
- 
  
    
      .deserialize(h)  ⇒ Track 
    
    
  
  
  
  
  
  
  
  
  
    Parses a track from a nested Hash that uses string keys. 
Instance Method Summary collapse
- 
  
    
      #initialize  ⇒ Track 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Track. 
- 
  
    
      #serialize  ⇒ Hash<String, Object> 
    
    
  
  
  
  
  
  
  
  
  
    Serializes the track to a nested Hash that uses string keys. 
Constructor Details
#initialize ⇒ Track
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_at ⇒ optional, DateTime
Returns 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_by ⇒ optional, String
Returns 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_id ⇒ optional, String
Returns 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 | 
#applemusic ⇒ optional, TrackAppleMusic
Returns Apple Music-specific metadata.
| 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_ids ⇒ Array<String>
Returns The (internal) artist 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 | 
#composer_ids ⇒ optional, Array<String>
Returns 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_ms ⇒ optional, Float
Returns 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 | 
#explicit ⇒ optional, Boolean
Returns 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 | 
#genres ⇒ optional, Array<String>
Returns 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 | 
#isrc ⇒ optional, String
Returns 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 | 
#name ⇒ String
Returns 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_at ⇒ optional, DateTime
Returns 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 | 
#spotify ⇒ optional, TrackSpotify
Returns Spotify-specific metadata.
| 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.
| 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
#serialize ⇒ Hash<String, Object>
Serializes the track to a nested Hash that uses string keys.
| 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 |