Class: Miteru::Crawler

Inherits:
Object
  • Object
show all
Defined in:
lib/miteru/crawler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCrawler

Returns a new instance of Crawler.



12
13
14
15
16
# File 'lib/miteru/crawler.rb', line 12

def initialize
  @downloader = Downloader.new(Miteru.configuration.download_to)
  @feeds = Feeds.new
  @notifier = Notifier.new
end

Instance Attribute Details

#downloaderObject (readonly)

Returns the value of attribute downloader.



9
10
11
# File 'lib/miteru/crawler.rb', line 9

def downloader
  @downloader
end

#feedsObject (readonly)

Returns the value of attribute feeds.



10
11
12
# File 'lib/miteru/crawler.rb', line 10

def feeds
  @feeds
end

Class Method Details

.executeObject



52
53
54
# File 'lib/miteru/crawler.rb', line 52

def execute
  new.execute
end

Instance Method Details

#auto_download?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/miteru/crawler.rb', line 43

def auto_download?
  Miteru.configuration.auto_download?
end

#crawl(url) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/miteru/crawler.rb', line 18

def crawl(url)
  website = Website.new(url)
  downloader.download_kits(website.kits) if website.has_kits? && auto_download?
  notify(website) if website.has_kits? || verbose?
rescue OpenSSL::SSL::SSLError, HTTP::Error, Addressable::URI::InvalidURIError => _e
  nil
end

#executeObject



26
27
28
29
30
31
32
33
# File 'lib/miteru/crawler.rb', line 26

def execute
  suspicious_urls = feeds.suspicious_urls
  puts "Loaded #{suspicious_urls.length} URLs to crawl. (crawling in #{threads} threads)" if verbose?

  Parallel.each(suspicious_urls, in_threads: threads) do |url|
    crawl url
  end
end

#notify(website) ⇒ Object



39
40
41
# File 'lib/miteru/crawler.rb', line 39

def notify(website)
  @notifier.notify(url: website.url, kits: website.kits, message: website.message)
end

#threadsObject



35
36
37
# File 'lib/miteru/crawler.rb', line 35

def threads
  @threads ||= Miteru.configuration.threads
end

#verbose?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/miteru/crawler.rb', line 47

def verbose?
  Miteru.configuration.verbose?
end