Class: ESearchy::Docs
- Inherits:
-
Object
- Object
- ESearchy::Docs
- Defined in:
- lib/esearchy/docs.rb
Instance Attribute Summary collapse
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
-
#emails ⇒ Object
readonly
Returns the value of attribute emails.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Class Method Summary collapse
- .push(doc) ⇒ Object
-
.search(doc) ⇒ Object
Class methods.
Instance Method Summary collapse
-
#initialize(doc = nil, size = 10485760) ⇒ Docs
constructor
A new instance of Docs.
- #local_search ⇒ Object
- #merge(array) ⇒ Object
- #push(doc) ⇒ Object
- #search ⇒ Object
Constructor Details
#initialize(doc = nil, size = 10485760) ⇒ Docs
Returns a new instance of Docs.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/esearchy/docs.rb', line 40 def initialize(doc=nil, size = 10485760) case doc when Array @@documents = Queue.new self.merge doc else @@documents = doc || Queue.new end @size = size @emails = [] @results = [] @lock = Mutex.new end |
Instance Attribute Details
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
38 39 40 |
# File 'lib/esearchy/docs.rb', line 38 def documents @documents end |
#emails ⇒ Object (readonly)
Returns the value of attribute emails.
38 39 40 |
# File 'lib/esearchy/docs.rb', line 38 def emails @emails end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
38 39 40 |
# File 'lib/esearchy/docs.rb', line 38 def results @results end |
Class Method Details
.push(doc) ⇒ Object
64 65 66 |
# File 'lib/esearchy/docs.rb', line 64 def self.push(doc) push(doc) end |
.search(doc) ⇒ Object
Class methods
55 56 57 58 |
# File 'lib/esearchy/docs.rb', line 55 def self.search(doc) self.new(doc) search(doc) end |
Instance Method Details
#local_search ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/esearchy/docs.rb', line 72 def local_search threads = [] while @documents.size >=1 threads << Thread.new do doc = @@documents.pop detect_type(doc.split(".")[-1], doc) end threads.each {|t| t.join } if @threads != nil end end |
#merge(array) ⇒ Object
60 61 62 |
# File 'lib/esearchy/docs.rb', line 60 def merge(array) array.each {|a| push(a) } end |
#push(doc) ⇒ Object
68 69 70 |
# File 'lib/esearchy/docs.rb', line 68 def push(doc) @@documents.push(doc) end |
#search ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/esearchy/docs.rb', line 83 def search threads = [] while @@documents.size >=1 threads << Thread.new do document = @@documents.pop url = document[0].gsub(' ','+') format = document[1] if data = download(url) name = save_to_disk(url, format, data) detect_type(format,name) remove_from_disk(name) end end threads.each {|t| t.join } if threads != nil end end |