Class: ESearchy
- Inherits:
-
Object
- Object
- ESearchy
- Defined in:
- lib/esearchy.rb
Constant Summary collapse
- LIBRARY =
1- APP =
2- LOG =
Logger.new(1, $stdout)
- DEFAULT_ENGINES =
{"Google" => Google, "Bing" => Bing, "Yahoo" => Yahoo, "PGP" => PGP, "LinkedIn" => Linkedin }
Instance Attribute Summary collapse
-
#depth_search ⇒ Object
Returns the value of attribute depth_search.
-
#engines ⇒ Object
Returns the value of attribute engines.
-
#maxhits ⇒ Object
Returns the value of attribute maxhits.
-
#query ⇒ Object
Returns the value of attribute query.
-
#threads ⇒ Object
Returns the value of attribute threads.
Class Method Summary collapse
Instance Method Summary collapse
- #bing_key=(value) ⇒ Object
- #clean(&block) ⇒ Object
- #company_name(company) ⇒ Object (also: #company_name=)
- #emails ⇒ Object
- #filter(regex) ⇒ Object
-
#initialize(options = {}, &block) ⇒ ESearchy
constructor
A new instance of ESearchy.
- #linkedin_credentials(user, pass) ⇒ Object (also: #linkedin_credentials=)
- #log_file=(value) ⇒ Object
- #log_type=(value) ⇒ Object
- #save_to_file(file) ⇒ Object
- #search(query = nil) ⇒ Object
- #yahoo_key=(value) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ ESearchy
Returns a new instance of ESearchy.
21 22 23 24 25 26 27 28 29 |
# File 'lib/esearchy.rb', line 21 def initialize(={}, &block) @query = [:query] @depth_search = [:depth] || true @maxhits = [:maxhits] @engines = [:engines] || DEFAULT_ENGINES @engines.each {|n,e| @engines[n] = e.new(@maxhits)} @threads = Array.new block.call(self) if block_given? end |
Instance Attribute Details
#depth_search ⇒ Object
Returns the value of attribute depth_search.
30 31 32 |
# File 'lib/esearchy.rb', line 30 def depth_search @depth_search end |
#engines ⇒ Object
Returns the value of attribute engines.
30 31 32 |
# File 'lib/esearchy.rb', line 30 def engines @engines end |
#maxhits ⇒ Object
Returns the value of attribute maxhits.
31 32 33 |
# File 'lib/esearchy.rb', line 31 def maxhits @maxhits end |
#query ⇒ Object
Returns the value of attribute query.
30 31 32 |
# File 'lib/esearchy.rb', line 30 def query @query end |
#threads ⇒ Object
Returns the value of attribute threads.
30 31 32 |
# File 'lib/esearchy.rb', line 30 def threads @threads end |
Class Method Details
.create(query = nil, &block) ⇒ Object
91 92 93 94 95 |
# File 'lib/esearchy.rb', line 91 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
66 67 68 |
# File 'lib/esearchy.rb', line 66 def bing_key=(value) @engines['Bing'].appid = value end |
#clean(&block) ⇒ Object
50 51 52 53 54 |
# File 'lib/esearchy.rb', line 50 def clean(&block) emails.each do |e| e.delete_if block.call end end |
#company_name(company) ⇒ Object Also known as: company_name=
76 77 78 |
# File 'lib/esearchy.rb', line 76 def company_name (company) @engines['LinkedIn'].company_name = company end |
#emails ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/esearchy.rb', line 42 def emails emails = [] @engines.each do |n,e| emails.concat(@engines[n].emails).uniq! end emails end |
#filter(regex) ⇒ Object
87 88 89 |
# File 'lib/esearchy.rb', line 87 def filter(regex) emails.each.select { |email| email =~ regex } end |
#linkedin_credentials(user, pass) ⇒ Object Also known as: linkedin_credentials=
70 71 72 73 |
# File 'lib/esearchy.rb', line 70 def linkedin_credentials(user, pass) @engines['LinkedIn'].username = user @engines['LinkedIn'].password = pass end |
#log_file=(value) ⇒ Object
14 15 16 |
# File 'lib/esearchy.rb', line 14 def log_file=(value) ESearchy::LOG.file = value end |
#log_type=(value) ⇒ Object
10 11 12 |
# File 'lib/esearchy.rb', line 10 def log_type=(value) ESearchy::LOG.level = value end |
#save_to_file(file) ⇒ Object
81 82 83 84 85 |
# File 'lib/esearchy.rb', line 81 def save_to_file(file) open(file,"a") do |f| emails.each { |e| f << e + "\n" } end end |
#search(query = nil) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/esearchy.rb', line 33 def search(query=nil) @engines.each do |n,e| LOG.puts "+--- Launching Search for #{n} ---+\n" e.search(query || @query) e.search_depth if depth_search? LOG.puts "+--- Finishing Search for #{n} ---+\n" end end |
#yahoo_key=(value) ⇒ Object
62 63 64 |
# File 'lib/esearchy.rb', line 62 def yahoo_key=(value) @engines['Yahoo'].appid = value end |