24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/cookler.rb', line 24
def run
total_words = []
@pages.remove
@stats.remove
general_stime = Time.now.to_f
@targets.each do |target|
@threads << Thread.new(target) do |current_target|
current_target_stime = Time.now.to_f
current_target_words = _get_words_on_pages current_target
total_words += current_target_words
current_target_wstats = Hash[current_target_words.group_by{ |word| word.to_s.downcase}.map{ |word, instances| [word, instances.length] }.sort_by(&:last).reverse]
@stats.insert({:type => current_target[0], :duration => (Time.now.to_f - current_target_stime).to_s, :wstats => current_target_wstats})
end
end
@threads.each { |aThread| aThread.join }
general_wstats = Hash[total_words.group_by{ |word| word.to_s.downcase}.map{ |word, instances| [word, instances.length] }.sort_by(&:last).reverse]
@stats.insert({:type => :general, :duration => (Time.now.to_f - general_stime).to_s, :wstats => general_wstats})
end
|