Class: ESearchy::GenericEngine

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, start = 0, stop = nil, &block) ⇒ GenericEngine

Returns a new instance of GenericEngine.



4
5
6
7
8
9
10
11
12
13
# File 'lib/esearchy/genericengine.rb', line 4

def initialize(query, start = 0, stop = nil, &block)
  @query = CGI.escape(query) or raise ESearchyMissingQuery
  @company = ESearchy::Search.company || ""
  @start = start
  @totalhits = stop
  @documents = []
  self.class::TYPE < 2 ? @emails = [] : @people = []
  @results = []
  block.call(self) if block_given?
end

Instance Attribute Details

#documentsObject (readonly)

Returns the value of attribute documents.



15
16
17
# File 'lib/esearchy/genericengine.rb', line 15

def documents
  @documents
end

#emailsObject (readonly)

Returns the value of attribute emails.



17
18
19
# File 'lib/esearchy/genericengine.rb', line 17

def emails
  @emails
end

#peopleObject (readonly)

Returns the value of attribute people.



18
19
20
# File 'lib/esearchy/genericengine.rb', line 18

def people
  @people
end

#resultsObject (readonly)

Returns the value of attribute results.



16
17
18
# File 'lib/esearchy/genericengine.rb', line 16

def results
  @results
end

Instance Method Details

#company=(v) ⇒ Object



40
41
42
# File 'lib/esearchy/genericengine.rb', line 40

def company=(v)
  @company=v
end

#maxhits=(v) ⇒ Object



36
37
38
# File 'lib/esearchy/genericengine.rb', line 36

def maxhits=(v)
  @totalhits=v
end

#searchObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/esearchy/genericengine.rb', line 21

def search
  get self.class::ENGINE, self.class::PORT, 
      @querypath + @start.to_s, header() do |r|
    parse(r.body)
    D "Searching #{self.class} from #{@start} to #{calculate_top()}.\n"
    crawler(r.body.gsub(/<em>|<\/em>/,"").gsub(/<b>|<\/b>/,"")) unless @totalhits == 0
    @start = @start + self.class::NUM
    sleep(4) and search if @totalhits > @start
  end
end

#start=(v) ⇒ Object



32
33
34
# File 'lib/esearchy/genericengine.rb', line 32

def start=(v)
  @start=v
end