Class: Cookler
- Inherits:
-
Object
- Object
- Cookler
- Defined in:
- lib/cookler.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(targets, max_results = nil, dbURI = nil, anemone_db_uri = nil) ⇒ Cookler
constructor
A new instance of Cookler.
- #run ⇒ Object
Constructor Details
#initialize(targets, max_results = nil, dbURI = nil, anemone_db_uri = nil) ⇒ Cookler
Returns a new instance of Cookler.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cookler.rb', line 8 def initialize(targets, max_results=nil, dbURI=nil, anemone_db_uri=nil) @targets = targets @max_results = (max_results.nil? ? 15 : max_results) @db = (dbURI.nil? ? Mongo::Connection.new().db('cookler-db') : Mongo::Connection.from_uri(dbURI).db('cookler-db')) @anemone_db = (anemone_db_uri.nil? ? nil : Mongo::Connection.from_uri(anemone_db_uri).db('anemone')) @pages = @db['pages'] @stats = @db['stats'] @depth_limit = 3 @threads = [] end |
Class Method Details
.analyze(targets, max_results = nil, dbURI = nil, anemone_db_uri = nil) ⇒ Object
19 20 21 22 |
# File 'lib/cookler.rb', line 19 def self.analyze(targets, max_results=nil, dbURI=nil, anemone_db_uri=nil) cookler = self.new(targets, max_results, dbURI, anemone_db_uri) cookler.run end |
Instance Method Details
#run ⇒ Object
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 |