Class: Bookbinder::Spider
- Inherits:
-
Object
- Object
- Bookbinder::Spider
- Defined in:
- lib/bookbinder/spider.rb,
lib/bookbinder/stabilimentum.rb
Defined Under Namespace
Classes: Stabilimentum
Class Method Summary collapse
Instance Method Summary collapse
- #generate_sitemap(target_host, port) ⇒ Object
- #has_broken_links? ⇒ Boolean
-
#initialize(logger, app_dir: nil) ⇒ Spider
constructor
A new instance of Spider.
Constructor Details
#initialize(logger, app_dir: nil) ⇒ Spider
Returns a new instance of Spider.
10 11 12 13 14 |
# File 'lib/bookbinder/spider.rb', line 10 def initialize(logger, app_dir: nil) @logger = logger @app_dir = app_dir || raise('Spiders must be initialized with an app directory.') @broken_links = [] end |
Class Method Details
.prepend_location(location, url) ⇒ Object
33 34 35 |
# File 'lib/bookbinder/spider.rb', line 33 def self.prepend_location(location, url) "#{URI(location).path} => #{url}" end |
Instance Method Details
#generate_sitemap(target_host, port) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bookbinder/spider.rb', line 16 def generate_sitemap(target_host, port) temp_host = "localhost:#{port}" sieve = Sieve.new domain: "http://#{temp_host}" links = crawl_from "http://#{temp_host}/index.html", sieve @broken_links, working_links = links announce_broken_links @broken_links write_sitemap(target_host, temp_host, working_links) working_links end |
#has_broken_links? ⇒ Boolean
29 30 31 |
# File 'lib/bookbinder/spider.rb', line 29 def has_broken_links? @broken_links.any? { |link| !link.include?('#') } if @broken_links end |