Class: Snackhack2::Email
- Inherits:
-
Object
- Object
- Snackhack2::Email
- Defined in:
- lib/snackhack2/emails.rb
Instance Attribute Summary collapse
-
#max_depth ⇒ Object
Returns the value of attribute max_depth.
Instance Method Summary collapse
-
#initialize(site, save_file: true, max_depth: 2) ⇒ Email
constructor
A new instance of Email.
- #run ⇒ Object
Constructor Details
#initialize(site, save_file: true, max_depth: 2) ⇒ Email
Returns a new instance of Email.
9 10 11 12 13 |
# File 'lib/snackhack2/emails.rb', line 9 def initialize(site, save_file: true, max_depth: 2) @site = site @save_file = save_file @max_depth = max_depth end |
Instance Attribute Details
#max_depth ⇒ Object
Returns the value of attribute max_depth.
7 8 9 |
# File 'lib/snackhack2/emails.rb', line 7 def max_depth @max_depth end |
Instance Method Details
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/snackhack2/emails.rb', line 17 def run found_emails = [] Spidr.start_at(@site, max_depth: @max_depth) do |agent| agent.every_page do |page| body = page.to_s if body.scan(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}/) email = body.scan(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}/).uniq found_emails << email if !email.include?(found_emails) && !email.empty? end end end Snackhack2.file_save(@site, 'emails', found_emails.uniq.join("\n")) if @save_file end |