Class: Pandoru::Models::TrackExplanation

Inherits:
Base
  • Object
show all
Defined in:
lib/pandoru/models/track_explanation.rb

Overview

The result of track.explainTrack: the human-readable traits the Music Genome Project used to justify playing a track. This is the closest the API gets to exposing genome data — discrete trait tags, not a vector.

Instance Attribute Summary collapse

Attributes inherited from Base

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

date_field, field, fields, from_json_list, #initialize, #inspect, #populate_from_json, #to_h

Constructor Details

This class inherits a constructor from Pandoru::Models::Base

Instance Attribute Details

#explanationsObject

Returns the value of attribute explanations.



20
21
22
# File 'lib/pandoru/models/track_explanation.rb', line 20

def explanations
  @explanations
end

Class Method Details

.from_json(api_client, data) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/pandoru/models/track_explanation.rb', line 22

def self.from_json(api_client, data)
  return nil unless data
  instance = new(data, api_client)
  instance.explanations =
    FocusTrait.from_json_list(api_client, data['explanations'])
  instance
end

Instance Method Details

#focus_traitsObject

The genome-derived trait name strings, with the trailing filler entry removed. The API always appends a non-attribute entry as the last explanation (“…many other similarities identified in the Music Genome Project”); it carries no focusTraitId, so we drop it.



34
35
36
37
38
# File 'lib/pandoru/models/track_explanation.rb', line 34

def focus_traits
  traits = explanations || []
  traits = traits[0...-1] if traits.last && traits.last.focus_trait_id.nil?
  traits.map(&:focus_trait_name).compact
end