Class: Bookbinder::Spider
- Inherits:
-
Object
- Object
- Bookbinder::Spider
- Defined in:
- lib/bookbinder/spider.rb,
lib/bookbinder/stabilimentum.rb
Defined Under Namespace
Classes: Result, Stabilimentum
Class Method Summary collapse
Instance Method Summary collapse
- #generate_sitemap(target_host, port, streams, broken_link_exclusions: /(?!.*)/) ⇒ Object
-
#initialize(app_dir: nil) ⇒ Spider
constructor
A new instance of Spider.
Constructor Details
#initialize(app_dir: nil) ⇒ Spider
Returns a new instance of Spider.
34 35 36 |
# File 'lib/bookbinder/spider.rb', line 34 def initialize(app_dir: nil) @app_dir = app_dir || raise('Spiders must be initialized with an app directory.') end |
Class Method Details
.prepend_location(location, url) ⇒ Object
30 31 32 |
# File 'lib/bookbinder/spider.rb', line 30 def self.prepend_location(location, url) "#{URI(location).path} => #{url}" end |
Instance Method Details
#generate_sitemap(target_host, port, streams, broken_link_exclusions: /(?!.*)/) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bookbinder/spider.rb', line 38 def generate_sitemap(target_host, port, streams, broken_link_exclusions: /(?!.*)/) 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 sitemap_links = substitute_hostname(temp_host, target_host, working_links) public_broken_links = broken_links.reject {|l| l.match(broken_link_exclusions)} announce_broken_links(public_broken_links, streams) Result.new( public_broken_links, SitemapGenerator.new.generate(sitemap_links), app_dir ) end |