Module: Title::Processor
- Defined in:
- lib/title/processor.rb,
lib/title/processor/version.rb
Constant Summary collapse
- VERSION =
'0.1.3'
Class Method Summary collapse
Class Method Details
.process!(links = []) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/title/processor.rb', line 9 def self.process!(links = []) threads = [] titles = [] title_mutex = Mutex.new links.each do |link| threads << Thread.new(link, titles) do |l_link, l_titles| uri = URI(l_link) response = Net::HTTP.get(uri) title = Nokogiri::HTML::Document.parse(response).title title_mutex.synchronize { l_titles << title } end end threads.each(&:join) titles end |