Class: SpotifyWebApi::SectionObject

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/spotify_web_api/models/section_object.rb

Overview

SectionObject Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(start = SKIP, duration = SKIP, confidence = SKIP, loudness = SKIP, tempo = SKIP, tempo_confidence = SKIP, key = SKIP, key_confidence = SKIP, mode = SKIP, mode_confidence = SKIP, time_signature = SKIP, time_signature_confidence = SKIP) ⇒ SectionObject

Returns a new instance of SectionObject.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/spotify_web_api/models/section_object.rb', line 120

def initialize(start = SKIP, duration = SKIP, confidence = SKIP,
               loudness = SKIP, tempo = SKIP, tempo_confidence = SKIP,
               key = SKIP, key_confidence = SKIP, mode = SKIP,
               mode_confidence = SKIP, time_signature = SKIP,
               time_signature_confidence = SKIP)
  @start = start unless start == SKIP
  @duration = duration unless duration == SKIP
  @confidence = confidence unless confidence == SKIP
  @loudness = loudness unless loudness == SKIP
  @tempo = tempo unless tempo == SKIP
  @tempo_confidence = tempo_confidence unless tempo_confidence == SKIP
  @key = key unless key == SKIP
  @key_confidence = key_confidence unless key_confidence == SKIP
  @mode = mode unless mode == SKIP
  @mode_confidence = mode_confidence unless mode_confidence == SKIP
  @time_signature = time_signature unless time_signature == SKIP
  unless time_signature_confidence == SKIP
    @time_signature_confidence =
      time_signature_confidence
  end
end

Instance Attribute Details

#confidenceFloat

The confidence, from 0.0 to 1.0, of the reliability of the section’s “designation”.

Returns:

  • (Float)


23
24
25
# File 'lib/spotify_web_api/models/section_object.rb', line 23

def confidence
  @confidence
end

#durationFloat

The duration (in seconds) of the section.

Returns:

  • (Float)


18
19
20
# File 'lib/spotify_web_api/models/section_object.rb', line 18

def duration
  @duration
end

#keyInteger

The estimated overall key of the section. The values in this field ranging from 0 to 11 mapping to pitches using standard Pitch Class notation (E.g. 0 = C, 1 = C♯/D♭, 2 = D, and so on). If no key was detected, the value is -1.

Returns:

  • (Integer)


47
48
49
# File 'lib/spotify_web_api/models/section_object.rb', line 47

def key
  @key
end

#key_confidenceFloat

The confidence, from 0.0 to 1.0, of the reliability of the key. Songs with many key changes may correspond to low values in this field.

Returns:

  • (Float)


52
53
54
# File 'lib/spotify_web_api/models/section_object.rb', line 52

def key_confidence
  @key_confidence
end

#loudnessFloat

The overall loudness of the section in decibels (dB). Loudness values are useful for comparing relative loudness of sections within tracks.

Returns:

  • (Float)


28
29
30
# File 'lib/spotify_web_api/models/section_object.rb', line 28

def loudness
  @loudness
end

#modeModeEnum

Indicates the modality (major or minor) of a section, the type of scale from which its melodic content is derived. This field will contain a 0 for “minor”, a 1 for “major”, or a -1 for no result. Note that the major key (e.g. C major) could more likely be confused with the minor key at 3 semitones lower (e.g. A minor) as both keys carry the same pitches.

Returns:



60
61
62
# File 'lib/spotify_web_api/models/section_object.rb', line 60

def mode
  @mode
end

#mode_confidenceFloat

The confidence, from 0.0 to 1.0, of the reliability of the ‘mode`.

Returns:

  • (Float)


64
65
66
# File 'lib/spotify_web_api/models/section_object.rb', line 64

def mode_confidence
  @mode_confidence
end

#startFloat

The starting point (in seconds) of the section.

Returns:

  • (Float)


14
15
16
# File 'lib/spotify_web_api/models/section_object.rb', line 14

def start
  @start
end

#tempoFloat

The overall estimated tempo of the section in beats per minute (BPM). In musical terminology, tempo is the speed or pace of a given piece and derives directly from the average beat duration.

Returns:

  • (Float)


34
35
36
# File 'lib/spotify_web_api/models/section_object.rb', line 34

def tempo
  @tempo
end

#tempo_confidenceFloat

The confidence, from 0.0 to 1.0, of the reliability of the tempo. Some tracks contain tempo changes or sounds which don’t contain tempo (like pure speech) which would correspond to a low value in this field.

Returns:

  • (Float)


40
41
42
# File 'lib/spotify_web_api/models/section_object.rb', line 40

def tempo_confidence
  @tempo_confidence
end

#time_signatureInteger

An estimated time signature. The time signature (meter) is a notational convention to specify how many beats are in each bar (or measure). The time signature ranges from 3 to 7 indicating time signatures of “3/4”, to “7/4”.

Returns:

  • (Integer)


71
72
73
# File 'lib/spotify_web_api/models/section_object.rb', line 71

def time_signature
  @time_signature
end

#time_signature_confidenceFloat

The confidence, from 0.0 to 1.0, of the reliability of the ‘time_signature`. Sections with time signature changes may correspond to low values in this field.

Returns:

  • (Float)


77
78
79
# File 'lib/spotify_web_api/models/section_object.rb', line 77

def time_signature_confidence
  @time_signature_confidence
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/spotify_web_api/models/section_object.rb', line 143

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  start = hash.key?('start') ? hash['start'] : SKIP
  duration = hash.key?('duration') ? hash['duration'] : SKIP
  confidence = hash.key?('confidence') ? hash['confidence'] : SKIP
  loudness = hash.key?('loudness') ? hash['loudness'] : SKIP
  tempo = hash.key?('tempo') ? hash['tempo'] : SKIP
  tempo_confidence =
    hash.key?('tempo_confidence') ? hash['tempo_confidence'] : SKIP
  key = hash.key?('key') ? hash['key'] : SKIP
  key_confidence =
    hash.key?('key_confidence') ? hash['key_confidence'] : SKIP
  mode = hash.key?('mode') ? hash['mode'] : SKIP
  mode_confidence =
    hash.key?('mode_confidence') ? hash['mode_confidence'] : SKIP
  time_signature =
    hash.key?('time_signature') ? hash['time_signature'] : SKIP
  time_signature_confidence =
    hash.key?('time_signature_confidence') ? hash['time_signature_confidence'] : SKIP

  # Create object from extracted values.
  SectionObject.new(start,
                    duration,
                    confidence,
                    loudness,
                    tempo,
                    tempo_confidence,
                    key,
                    key_confidence,
                    mode,
                    mode_confidence,
                    time_signature,
                    time_signature_confidence)
end

.namesObject

A mapping from model property names to API property names.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/spotify_web_api/models/section_object.rb', line 80

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['start'] = 'start'
  @_hash['duration'] = 'duration'
  @_hash['confidence'] = 'confidence'
  @_hash['loudness'] = 'loudness'
  @_hash['tempo'] = 'tempo'
  @_hash['tempo_confidence'] = 'tempo_confidence'
  @_hash['key'] = 'key'
  @_hash['key_confidence'] = 'key_confidence'
  @_hash['mode'] = 'mode'
  @_hash['mode_confidence'] = 'mode_confidence'
  @_hash['time_signature'] = 'time_signature'
  @_hash['time_signature_confidence'] = 'time_signature_confidence'
  @_hash
end

.nullablesObject

An array for nullable fields



116
117
118
# File 'lib/spotify_web_api/models/section_object.rb', line 116

def self.nullables
  []
end

.optionalsObject

An array for optional fields



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/spotify_web_api/models/section_object.rb', line 98

def self.optionals
  %w[
    start
    duration
    confidence
    loudness
    tempo
    tempo_confidence
    key
    key_confidence
    mode
    mode_confidence
    time_signature
    time_signature_confidence
  ]
end