Class: BrowserCrawler::Followups::ScreenshotsIndexer

Inherits:
Object
  • Object
show all
Defined in:
lib/browser_crawler/followups/screenshots_indexer.rb

Overview

Indexes screenshots captured by the crawler, creates index.html from the captured screenshots. ERB Template can be provided that will receive the list of files.

Instance Method Summary collapse

Constructor Details

#initialize(template:) ⇒ ScreenshotsIndexer

Returns a new instance of ScreenshotsIndexer.



7
8
9
# File 'lib/browser_crawler/followups/screenshots_indexer.rb', line 7

def initialize(template:)
  @template = template || File.read(default_template_file)
end

Instance Method Details

#index_directory(path, file_mask: '*.png') ⇒ Object

Produce index.html with links to screenshots found in the ‘path` specified. Optionally file_mask can be provided to filter out files to be indexed.



13
14
15
16
17
18
19
# File 'lib/browser_crawler/followups/screenshots_indexer.rb', line 13

def index_directory(path, file_mask: '*.png')
  files = Dir[File.join(path, file_mask)].map { |file| File.basename(file) }
  html = render_index(files: files)
  index_path = File.join(path, 'index.html')
  File.write(index_path, html)
  index_path
end

#index_report(report) ⇒ Object



21
22
23
24
25
26
# File 'lib/browser_crawler/followups/screenshots_indexer.rb', line 21

def index_report(report)
  sorted_pages = Hash[report.pages.sort_by { |(k, _v)| k }]
  files = Hash[sorted_pages.map do |(k, _v)|
    k
  end]
end