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: 4) ⇒ Email
constructor
A new instance of Email.
- #run ⇒ Object
Constructor Details
#initialize(site, save_file: true, max_depth: 4) ⇒ Email
Returns a new instance of Email.
7 8 9 10 11 |
# File 'lib/snackhack2/emails.rb', line 7 def initialize(site, save_file: true, max_depth: 4) @site = site @save_file = save_file @max_depth = max_depth end |
Instance Attribute Details
#max_depth ⇒ Object
Returns the value of attribute max_depth.
5 6 7 |
# File 'lib/snackhack2/emails.rb', line 5 def max_depth @max_depth end |
Instance Method Details
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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 if !email.include?(found_emails) if !email.empty? found_emails << email end end end end end Snackhack2::file_save(@site, "emails", found_emails.uniq.join("\n")) if @save_file end |