Class: SpotifyWebApi::AudioAnalysisObject

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

Overview

AudioAnalysisObject Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(meta = SKIP, track = SKIP, bars = SKIP, beats = SKIP, sections = SKIP, segments = SKIP, tatums = SKIP) ⇒ AudioAnalysisObject

Returns a new instance of AudioAnalysisObject.



77
78
79
80
81
82
83
84
85
86
# File 'lib/spotify_web_api/models/audio_analysis_object.rb', line 77

def initialize(meta = SKIP, track = SKIP, bars = SKIP, beats = SKIP,
               sections = SKIP, segments = SKIP, tatums = SKIP)
  @meta = meta unless meta == SKIP
  @track = track unless track == SKIP
  @bars = bars unless bars == SKIP
  @beats = beats unless beats == SKIP
  @sections = sections unless sections == SKIP
  @segments = segments unless segments == SKIP
  @tatums = tatums unless tatums == SKIP
end

Instance Attribute Details

#barsArray[TimeIntervalObject]

The time intervals of the bars throughout the track. A bar (or measure) is a segment of time defined as a given number of beats.

Returns:



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

def bars
  @bars
end

#beatsArray[TimeIntervalObject]

The time intervals of beats throughout the track. A beat is the basic time unit of a piece of music; for example, each tick of a metronome. Beats are typically multiples of tatums.

Returns:



29
30
31
# File 'lib/spotify_web_api/models/audio_analysis_object.rb', line 29

def beats
  @beats
end

#metaMeta

TODO: Write general description for this method

Returns:



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

def meta
  @meta
end

#sectionsArray[SectionObject]

Sections are defined by large variations in rhythm or timbre, e.g. chorus, verse, bridge, guitar solo, etc. Each section contains its own descriptions of tempo, key, mode, time_signature, and loudness.

Returns:



35
36
37
# File 'lib/spotify_web_api/models/audio_analysis_object.rb', line 35

def sections
  @sections
end

#segmentsArray[SegmentObject]

Each segment contains a roughly conisistent sound throughout its duration.

Returns:



39
40
41
# File 'lib/spotify_web_api/models/audio_analysis_object.rb', line 39

def segments
  @segments
end

#tatumsArray[TimeIntervalObject]

A tatum represents the lowest regular pulse train that a listener intuitively infers from the timing of perceived musical events (segments).

Returns:



44
45
46
# File 'lib/spotify_web_api/models/audio_analysis_object.rb', line 44

def tatums
  @tatums
end

#trackTrack

TODO: Write general description for this method

Returns:



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

def track
  @track
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/spotify_web_api/models/audio_analysis_object.rb', line 89

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  meta = Meta.from_hash(hash['meta']) if hash['meta']
  track = Track.from_hash(hash['track']) if hash['track']
  # Parameter is an array, so we need to iterate through it
  bars = nil
  unless hash['bars'].nil?
    bars = []
    hash['bars'].each do |structure|
      bars << (TimeIntervalObject.from_hash(structure) if structure)
    end
  end

  bars = SKIP unless hash.key?('bars')
  # Parameter is an array, so we need to iterate through it
  beats = nil
  unless hash['beats'].nil?
    beats = []
    hash['beats'].each do |structure|
      beats << (TimeIntervalObject.from_hash(structure) if structure)
    end
  end

  beats = SKIP unless hash.key?('beats')
  # Parameter is an array, so we need to iterate through it
  sections = nil
  unless hash['sections'].nil?
    sections = []
    hash['sections'].each do |structure|
      sections << (SectionObject.from_hash(structure) if structure)
    end
  end

  sections = SKIP unless hash.key?('sections')
  # Parameter is an array, so we need to iterate through it
  segments = nil
  unless hash['segments'].nil?
    segments = []
    hash['segments'].each do |structure|
      segments << (SegmentObject.from_hash(structure) if structure)
    end
  end

  segments = SKIP unless hash.key?('segments')
  # Parameter is an array, so we need to iterate through it
  tatums = nil
  unless hash['tatums'].nil?
    tatums = []
    hash['tatums'].each do |structure|
      tatums << (TimeIntervalObject.from_hash(structure) if structure)
    end
  end

  tatums = SKIP unless hash.key?('tatums')

  # Create object from extracted values.
  AudioAnalysisObject.new(meta,
                          track,
                          bars,
                          beats,
                          sections,
                          segments,
                          tatums)
end

.namesObject

A mapping from model property names to API property names.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/spotify_web_api/models/audio_analysis_object.rb', line 47

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['meta'] = 'meta'
  @_hash['track'] = 'track'
  @_hash['bars'] = 'bars'
  @_hash['beats'] = 'beats'
  @_hash['sections'] = 'sections'
  @_hash['segments'] = 'segments'
  @_hash['tatums'] = 'tatums'
  @_hash
end

.nullablesObject

An array for nullable fields



73
74
75
# File 'lib/spotify_web_api/models/audio_analysis_object.rb', line 73

def self.nullables
  []
end

.optionalsObject

An array for optional fields



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/spotify_web_api/models/audio_analysis_object.rb', line 60

def self.optionals
  %w[
    meta
    track
    bars
    beats
    sections
    segments
    tatums
  ]
end