Class: TweetToSounds::VolumeGetter
- Inherits:
-
Object
- Object
- TweetToSounds::VolumeGetter
- Defined in:
- lib/tweet_to_sounds/volume_getter.rb
Instance Method Summary collapse
- #get_volumes ⇒ Object
-
#initialize(sounds) ⇒ VolumeGetter
constructor
A new instance of VolumeGetter.
Constructor Details
#initialize(sounds) ⇒ VolumeGetter
Returns a new instance of VolumeGetter.
3 4 5 |
# File 'lib/tweet_to_sounds/volume_getter.rb', line 3 def initialize(sounds) @sounds = sounds end |
Instance Method Details
#get_volumes ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/tweet_to_sounds/volume_getter.rb', line 7 def get_volumes volumes = [] key = TweetToSounds.freesound_api_key threads = @sounds.map do |sound| Thread.new(sound) do |s| Thread.current[:results] = \ Net::HTTP.get(URI("http://www.freesound.org/api/sounds/#{sound.id}/analysis/lowlevel/average_loudness/?api_key=#{key}")).to_f.round(2) end end volumes = threads.flat_map { |t| t.join; t[:results] } end |