Class: ESearchy

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ ESearchy

Returns a new instance of ESearchy.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/esearchy.rb', line 5

def initialize(options={}, &block)
  @query = options[:query]
  @depth_search = options[:depth] || true
  @maxhits = options[:maxhits]
  @engines = options[:engines] || {"Google" => Google, 
                                   "Bing" => Bing, 
                                   "Yahoo" => Yahoo,
                                   "PGP" => PGP,
                                   "LinkedIn" => Linkedin }
  @engines.each {|n,e| @engines[n] = e.new(@maxhits)}
  @emails = Array.new
  @threads = Array.new
  block.call(self) if block_given?
end

Instance Attribute Details

#depth_searchObject

Returns the value of attribute depth_search.



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

def depth_search
  @depth_search
end

#enginesObject

Returns the value of attribute engines.



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

def engines
  @engines
end

#maxhitsObject

Returns the value of attribute maxhits.



20
21
22
# File 'lib/esearchy.rb', line 20

def maxhits
  @maxhits
end

#queryObject

Returns the value of attribute query.



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

def query
  @query
end

#threadsObject

Returns the value of attribute threads.



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

def threads
  @threads
end

Class Method Details

.create(query = nil, &block) ⇒ Object



79
80
81
82
83
# File 'lib/esearchy.rb', line 79

def self.create(query=nil, &block)
  self.new :query => query do |search|
    block.call(search) if block_given?
  end
end

Instance Method Details

#bing_key=(value) ⇒ Object



54
55
56
# File 'lib/esearchy.rb', line 54

def bing_key=(value)
  @engines['Bing'].appid = value
end

#clean(&block) ⇒ Object



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

def clean(&block)
  emails.each do |e|
    e.delete_if block.call
  end
end

#company_name(company) ⇒ Object Also known as: company_name=



64
65
66
# File 'lib/esearchy.rb', line 64

def company_name (company)
  @engines['LinkedIn'].company_name = company
end

#emailsObject



31
32
33
34
35
36
# File 'lib/esearchy.rb', line 31

def emails
  @engines.each do |n,e|
    @emails.concat(e.emails).uniq!
  end
  @emails
end

#filter(regex) ⇒ Object



75
76
77
# File 'lib/esearchy.rb', line 75

def filter(regex)
  emails.each.select { |email| email =~ regex }
end

#linkedin_credentials(user, pass) ⇒ Object Also known as: linkedin_credentials=



58
59
60
61
# File 'lib/esearchy.rb', line 58

def linkedin_credentials(user, pass)
  @engines['LinkedIn'].username = user
  @engines['LinkedIn'].password = pass
end

#save_to_file(file) ⇒ Object



69
70
71
72
73
# File 'lib/esearchy.rb', line 69

def save_to_file(file)
  open(file,"a") do |f|
    emails.each { |e| f << e + "\n" }
  end
end

#search(query = nil) ⇒ Object



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

def search(query=nil)
  @engines.each do |n,e|
    puts "+--- Launching Search for #{n} ---+\n"
    e.search(query || @query)
    e.search_depth if depth_search?
    puts "+--- Finishing Search for #{n} ---+\n"
  end
end

#yahoo_key=(value) ⇒ Object



50
51
52
# File 'lib/esearchy.rb', line 50

def yahoo_key=(value)
  @engines['Yahoo'].appid = value
end