Class: BrowserCrawler::Followups::WraithIntegrator
- Inherits:
-
Object
- Object
- BrowserCrawler::Followups::WraithIntegrator
- Defined in:
- lib/browser_crawler/followups/wraith_integrator.rb
Overview
Updates the :paths section of the Wraith’s config file.
Instance Method Summary collapse
-
#initialize(report:) ⇒ WraithIntegrator
constructor
A new instance of WraithIntegrator.
- #named_pages ⇒ Object
-
#paths(with_suffix: nil) ⇒ Hash
Sorted hash of page_name => path pair values appended with optional suffix.
- #sorted_pages ⇒ Object
- #update_config(wraith_config_file, path_suffix: nil) ⇒ Object
Constructor Details
#initialize(report:) ⇒ WraithIntegrator
Returns a new instance of WraithIntegrator.
8 9 10 11 12 13 14 |
# File 'lib/browser_crawler/followups/wraith_integrator.rb', line 8 def initialize(report:) @report = if report.respond_to?(:pages) report else YAML.safe_load(report, [Symbol]).symbolize_keys end end |
Instance Method Details
#named_pages ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/browser_crawler/followups/wraith_integrator.rb', line 28 def named_pages @report[:pages].each_with_object({}) do |(page_url, _links), h| page_path = URI(page_url.to_s).path page_name = page_path.parameterize h[page_name] = page_path end end |
#paths(with_suffix: nil) ⇒ Hash
Returns sorted hash of page_name => path pair values appended with optional suffix. Page name equals to path which makes it easy to navigate the page from the Wraith gallery.
24 25 26 |
# File 'lib/browser_crawler/followups/wraith_integrator.rb', line 24 def paths(with_suffix: nil) Hash[sorted_pages.map { |(k, v)| [k, "#{v}#{with_suffix}"] }] end |
#sorted_pages ⇒ Object
36 37 38 |
# File 'lib/browser_crawler/followups/wraith_integrator.rb', line 36 def sorted_pages Hash[named_pages.sort_by { |(k, _v)| k }] end |
#update_config(wraith_config_file, path_suffix: nil) ⇒ Object
16 17 18 19 20 |
# File 'lib/browser_crawler/followups/wraith_integrator.rb', line 16 def update_config(wraith_config_file, path_suffix: nil) config = YAML.safe_load(File.read(wraith_config_file)) config['paths'] = paths(with_suffix: path_suffix) File.write(wraith_config_file, config.to_yaml) end |