Class: ESearchy::Docs

Inherits:
Object
  • Object
show all
Defined in:
lib/esearchy/docs.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#documentsObject (readonly)

Returns the value of attribute documents.



38
39
40
# File 'lib/esearchy/docs.rb', line 38

def documents
  @documents
end

#emailsObject (readonly)

Returns the value of attribute emails.



38
39
40
# File 'lib/esearchy/docs.rb', line 38

def emails
  @emails
end

#resultsObject (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_searchObject



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

#searchObject



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