Class: TweetToSounds::SoundFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/tweet_to_sounds/sound_finder.rb

Instance Method Summary collapse

Constructor Details

#initialize(keywords) ⇒ SoundFinder

Returns a new instance of SoundFinder.



3
4
5
# File 'lib/tweet_to_sounds/sound_finder.rb', line 3

def initialize(keywords)
  @keywords = keywords
end

Instance Method Details

#soundsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tweet_to_sounds/sound_finder.rb', line 11

def sounds
  @sounds ||= begin
    keywords = pick_keywords(@keywords)
    threads = keywords.map do |keyword|
      Thread.new(keyword) do |kw|
        Thread.current[:results] = \
          pick_results TweetToSounds.freesound.advanced_search(kw)
      end
    end
    results = threads.flat_map { |t| t.join; t[:results] }
    stable_sample results, TweetToSounds.number_of_sounds
  end
end

#urlsObject



7
8
9
# File 'lib/tweet_to_sounds/sound_finder.rb', line 7

def urls
  sounds.map &:preview_hq_mp3
end