Class: Echonest::Analysis
- Inherits:
-
Object
- Object
- Echonest::Analysis
- Defined in:
- lib/echonest/analysis.rb
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Class Method Summary collapse
Instance Method Summary collapse
- #album ⇒ Object
- #artist ⇒ Object
- #bars ⇒ Object
- #beats ⇒ Object
- #duration ⇒ Object
- #end_of_fade_in ⇒ Object
-
#initialize(json) ⇒ Analysis
constructor
A new instance of Analysis.
- #key ⇒ Object
- #loudness ⇒ Object
- #meta_info ⇒ Object
- #mode ⇒ Object
- #sections ⇒ Object
- #segments ⇒ Object
- #start_of_fade_out ⇒ Object
- #tatums ⇒ Object
- #tempo ⇒ Object
- #time_signature ⇒ Object
- #title ⇒ Object
- #track_info ⇒ Object
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
#json ⇒ Object (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
#album ⇒ Object
25 26 27 |
# File 'lib/echonest/analysis.rb', line 25 def album ['album'] end |
#artist ⇒ Object
21 22 23 |
# File 'lib/echonest/analysis.rb', line 21 def artist ['artist'] end |
#bars ⇒ Object
65 66 67 68 69 |
# File 'lib/echonest/analysis.rb', line 65 def @body['bars'].map do || Bar.new(['start'], ['duration'], ['confidence']) end end |
#beats ⇒ Object
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 |
#duration ⇒ Object
37 38 39 |
# File 'lib/echonest/analysis.rb', line 37 def duration track_info['duration'] end |
#end_of_fade_in ⇒ Object
41 42 43 |
# File 'lib/echonest/analysis.rb', line 41 def end_of_fade_in track_info['end_of_fade_in'] end |
#key ⇒ Object
45 46 47 |
# File 'lib/echonest/analysis.rb', line 45 def key track_info['key'] end |
#loudness ⇒ Object
49 50 51 |
# File 'lib/echonest/analysis.rb', line 49 def loudness track_info['loudness'] end |
#meta_info ⇒ Object
110 111 112 |
# File 'lib/echonest/analysis.rb', line 110 def @body['meta'] end |
#mode ⇒ Object
53 54 55 |
# File 'lib/echonest/analysis.rb', line 53 def mode track_info['mode'] end |
#sections ⇒ Object
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 |
#segments ⇒ Object
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_out ⇒ Object
57 58 59 |
# File 'lib/echonest/analysis.rb', line 57 def start_of_fade_out track_info['start_of_fade_out'] end |
#tatums ⇒ Object
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 |
#tempo ⇒ Object
33 34 35 |
# File 'lib/echonest/analysis.rb', line 33 def tempo track_info['tempo'] end |
#time_signature ⇒ Object
61 62 63 |
# File 'lib/echonest/analysis.rb', line 61 def time_signature track_info['time_signature'] end |
#title ⇒ Object
29 30 31 |
# File 'lib/echonest/analysis.rb', line 29 def title ['title'] end |
#track_info ⇒ Object
106 107 108 |
# File 'lib/echonest/analysis.rb', line 106 def track_info @body['track'] end |