Class: WebMole::Scraper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scrape_option, pattern, gathering_mode = false) ⇒ Scraper

Returns a new instance of Scraper.



7
8
9
10
11
12
# File 'lib/webmole/scraper.rb', line 7

def initialize(scrape_option, pattern, gathering_mode = false)
  @scrape_option = scrape_option
  @pattern = pattern ? Regexp.new(pattern) : nil
  @matches = Hash.new { |h, k| h[k] = Set.new }
  @gathering_mode = gathering_mode
end

Instance Attribute Details

#matchesObject (readonly)

Returns the value of attribute matches.



5
6
7
# File 'lib/webmole/scraper.rb', line 5

def matches
  @matches
end

Instance Method Details

#scrape(text, url) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/webmole/scraper.rb', line 14

def scrape(text, url)
  case @scrape_option
  when :emails
    find_emails(text, url)
  when :phone_numbers
    find_phone_numbers(text, url)
  when :urls
    find_urls(text, url)
  when :social_media
    find_social_media(text, url)
  when :addresses
    find_addresses(text, url)
  when :credit_cards
    find_credit_cards(text, url)
  when :custom
    find_matches(text, url)
  end
end