Class: ESearchy
- Inherits:
-
Object
- Object
- ESearchy
- Defined in:
- lib/esearchy.rb
Constant Summary collapse
- LIBRARY =
Constants
1- APP =
2- LOG =
Logger.new(1, $stdout)
- BUGMENOT =
BMN::fetch_user("linkedin.com")
- DEFAULT_ENGINES =
[:Google, :Bing, :Yahoo, :PGP, :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
- #eng(arr) ⇒ Object
- #filter(regex) ⇒ Object
-
#initialize(options = {}, &block) ⇒ ESearchy
constructor
A new instance of ESearchy.
- #linkedin_credentials(*args) ⇒ Object (also: #linkedin_credentials=)
- #log_file=(value) ⇒ Object
-
#log_type=(value) ⇒ Object
End Constants.
- #save_to_file(file) ⇒ Object
- #search(query = nil) ⇒ Object
- #search_engine(key, value) ⇒ Object
- #yahoo_key=(value) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ ESearchy
Returns a new instance of ESearchy.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/esearchy.rb', line 30 def initialize(={}, &block) @query = [:query] @depth_search = [:depth] || true @maxhits = [:maxhits] || 0 @engines = [:engines] ? eng([:engines]) : { :Google => Google, :Bing => Bing, :Yahoo => Yahoo, :PGP => PGP, :LinkedIn => LinkedIn } @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.
45 46 47 |
# File 'lib/esearchy.rb', line 45 def depth_search @depth_search end |
#engines ⇒ Object
Returns the value of attribute engines.
45 46 47 |
# File 'lib/esearchy.rb', line 45 def engines @engines end |
#maxhits ⇒ Object
Returns the value of attribute maxhits.
46 47 48 |
# File 'lib/esearchy.rb', line 46 def maxhits @maxhits end |
#query ⇒ Object
Returns the value of attribute query.
45 46 47 |
# File 'lib/esearchy.rb', line 45 def query @query end |
#threads ⇒ Object
Returns the value of attribute threads.
45 46 47 |
# File 'lib/esearchy.rb', line 45 def threads @threads end |
Class Method Details
.create(query = nil, &block) ⇒ Object
135 136 137 138 139 |
# File 'lib/esearchy.rb', line 135 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
81 82 83 |
# File 'lib/esearchy.rb', line 81 def bing_key=(value) @engines[:Bing].appid = value end |
#clean(&block) ⇒ Object
65 66 67 68 69 |
# File 'lib/esearchy.rb', line 65 def clean(&block) emails.each do |e| e.delete_if block.call end end |
#company_name(company) ⇒ Object Also known as: company_name=
99 100 101 |
# File 'lib/esearchy.rb', line 99 def company_name(company) @engines[:LinkedIn].company_name = company end |
#emails ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/esearchy.rb', line 57 def emails emails = [] @engines.each do |n,e| emails.concat(@engines[n].emails).uniq! end emails end |
#eng(arr) ⇒ Object
24 25 26 |
# File 'lib/esearchy.rb', line 24 def eng(arr) hsh = {}; arr.each {|e| hsh[e] = instance_eval "#{e}"}; hsh end |
#filter(regex) ⇒ Object
131 132 133 |
# File 'lib/esearchy.rb', line 131 def filter(regex) emails.each.select { |email| email =~ regex } end |
#linkedin_credentials(*args) ⇒ Object Also known as: linkedin_credentials=
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/esearchy.rb', line 85 def linkedin_credentials(*args) if args.size == 2 @engines[:LinkedIn].username = args[0] @engines[:LinkedIn].password = args[1] return true elsif args.size ==1 @engines[:LinkedIn].username = args[0][0] @engines[:LinkedIn].password = args[0][1] return true end false end |
#log_file=(value) ⇒ Object
20 21 22 |
# File 'lib/esearchy.rb', line 20 def log_file=(value) ESearchy::LOG.file = value end |
#log_type=(value) ⇒ Object
End Constants
16 17 18 |
# File 'lib/esearchy.rb', line 16 def log_type=(value) ESearchy::LOG.level = value end |
#save_to_file(file) ⇒ Object
125 126 127 128 129 |
# File 'lib/esearchy.rb', line 125 def save_to_file(file) open(file,"a") do |f| emails.each { |e| f << e + "\n" } end end |
#search(query = nil) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/esearchy.rb', line 48 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 |
#search_engine(key, value) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/esearchy.rb', line 104 def search_engine(key, value) if [:Google, :Bing, :Yahoo, :PGP, :LinkedIn, :GoogleGroups].include?(key) if value == true unless @engines[key] @engines[key] = instance_eval "#{key}.new(@maxhits)" end elsif value == false @engines.delete(key) end else raise(ArgumentError, "No plugin with that Key") end end |
#yahoo_key=(value) ⇒ Object
77 78 79 |
# File 'lib/esearchy.rb', line 77 def yahoo_key=(value) @engines[:Yahoo].appid = value end |