lib/scissor/echonest.rb in scissor-echonest-0.0.6 vs lib/scissor/echonest.rb in scissor-echonest-0.0.7
- old
+ new
@@ -8,22 +8,22 @@
end
class Chunk
class << self
attr_accessor :echonest_api_key
- end
- def echonest
- Echonest(self.class.echonest_api_key)
+ def echonest
+ @echonest ||= Echonest(echonest_api_key)
+ end
end
def beats
tempfile_for_echonest do |tmpfile|
chunks = []
scissor = to_file(tmpfile, :bitrate => '64k')
- beats = echonest.get_beats(tmpfile)
+ beats = self.class.echonest.get_beats(tmpfile)
if beats.size != 0
chunk = self[0, beats.first.start]
beat = Beat.new(beats.first.start, 1.0)
chunk.set_delegate(beat)
@@ -43,10 +43,10 @@
def segments
tempfile_for_echonest do |tmpfile|
scissor = to_file(tmpfile, :bitrate => '64k')
- segments = echonest.get_segments(tmpfile)
+ segments = self.class.echonest.get_segments(tmpfile)
segments.inject([]) do |chunks, segment|
chunk = self[segment.start, segment.duration]
chunk.set_delegate(segment)
chunks << chunk
chunks