Class: Echonest::Analysis

Inherits:
Object
  • Object
show all
Defined in:
lib/echonest/analysis.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Analysis

Returns a new instance of Analysis.



8
9
10
11
# File 'lib/echonest/analysis.rb', line 8

def initialize(json)
  @json = json
  @body = JSON.parse(@json)
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



6
7
8
# File 'lib/echonest/analysis.rb', line 6

def json
  @json
end

Class Method Details

.new_from_url(url) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/echonest/analysis.rb', line 13

def self.new_from_url(url)
  if OpenURI::Options.has_key? :ssl_verify_mode
    new(open(url, 'r', { :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE }).read)
  else
    new(open(url).read)
  end
end

Instance Method Details

#albumObject



25
26
27
# File 'lib/echonest/analysis.rb', line 25

def album
  meta_info['album']
end

#artistObject



21
22
23
# File 'lib/echonest/analysis.rb', line 21

def artist
  meta_info['artist']
end

#barsObject



65
66
67
68
69
# File 'lib/echonest/analysis.rb', line 65

def bars
  @body['bars'].map do |bar|
    Bar.new(bar['start'], bar['duration'], bar['confidence'])
  end
end

#beatsObject



71
72
73
74
75
# File 'lib/echonest/analysis.rb', line 71

def beats
  @body['beats'].map do |beat|
    Beat.new(beat['start'], beat['duration'], beat['confidence'])
  end
end

#durationObject



37
38
39
# File 'lib/echonest/analysis.rb', line 37

def duration
  track_info['duration']
end

#end_of_fade_inObject



41
42
43
# File 'lib/echonest/analysis.rb', line 41

def end_of_fade_in
  track_info['end_of_fade_in']
end

#keyObject



45
46
47
# File 'lib/echonest/analysis.rb', line 45

def key
  track_info['key']
end

#loudnessObject



49
50
51
# File 'lib/echonest/analysis.rb', line 49

def loudness
  track_info['loudness']
end

#meta_infoObject



110
111
112
# File 'lib/echonest/analysis.rb', line 110

def meta_info
  @body['meta']
end

#modeObject



53
54
55
# File 'lib/echonest/analysis.rb', line 53

def mode
  track_info['mode']
end

#sectionsObject



77
78
79
80
81
# File 'lib/echonest/analysis.rb', line 77

def sections
  @body['sections'].map do |section|
    Section.new(section['start'], section['duration'], section['confidence'])
  end
end

#segmentsObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/echonest/analysis.rb', line 89

def segments
  @body['segments'].map do |segment|
    loudness = Loudness.new(0.0, segment['loudness_start'])
    max_loudness = Loudness.new(segment['loudness_max_time'], segment['loudness_max'])

    Segment.new(
      segment['start'],
      segment['duration'],
      segment['confidence'],
      loudness,
      max_loudness,
      segment['pitches'],
      segment['timbre']
      )
  end
end

#start_of_fade_outObject



57
58
59
# File 'lib/echonest/analysis.rb', line 57

def start_of_fade_out
  track_info['start_of_fade_out']
end

#tatumsObject



83
84
85
86
87
# File 'lib/echonest/analysis.rb', line 83

def tatums
  @body['tatums'].map do |tatum|
    Tatum.new(tatum['start'], tatum['duration'], tatum['confidence'])
  end
end

#tempoObject



33
34
35
# File 'lib/echonest/analysis.rb', line 33

def tempo
  track_info['tempo']
end

#time_signatureObject



61
62
63
# File 'lib/echonest/analysis.rb', line 61

def time_signature
  track_info['time_signature']
end

#titleObject



29
30
31
# File 'lib/echonest/analysis.rb', line 29

def title
  meta_info['title']
end

#track_infoObject



106
107
108
# File 'lib/echonest/analysis.rb', line 106

def track_info
  @body['track']
end