Class: BrowserCrawler::EngineUtilities::PageInspector

Inherits:
Object
  • Object
show all
Includes:
HooksOperator, Capybara::DSL
Defined in:
lib/browser_crawler/engine_utilities/page_inspector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HooksOperator

#exchange_on_hooks, #with_hooks_for

Constructor Details

#initialize(link_inspector:, capybara_session:, report_store:) ⇒ PageInspector

Returns a new instance of PageInspector.



17
18
19
20
21
22
23
# File 'lib/browser_crawler/engine_utilities/page_inspector.rb', line 17

def initialize(link_inspector:, capybara_session:, report_store:)
  @link_inspector = link_inspector
  @capybara_session = capybara_session
  @report_store = report_store
  @scan_result = []
  @link_scanner = LinkScanner.new(link_inspector: link_inspector)
end

Instance Attribute Details

#capybara_sessionObject

Returns the value of attribute capybara_session.



11
12
13
# File 'lib/browser_crawler/engine_utilities/page_inspector.rb', line 11

def capybara_session
  @capybara_session
end

Returns the value of attribute link_inspector.



11
12
13
# File 'lib/browser_crawler/engine_utilities/page_inspector.rb', line 11

def link_inspector
  @link_inspector
end

Returns the value of attribute link_scanner.



11
12
13
# File 'lib/browser_crawler/engine_utilities/page_inspector.rb', line 11

def link_scanner
  @link_scanner
end

#report_storeObject

Returns the value of attribute report_store.



11
12
13
# File 'lib/browser_crawler/engine_utilities/page_inspector.rb', line 11

def report_store
  @report_store
end

#scan_resultObject

Returns the value of attribute scan_result.



11
12
13
# File 'lib/browser_crawler/engine_utilities/page_inspector.rb', line 11

def scan_result
  @scan_result
end

Instance Method Details

#before_page_scanObject



48
# File 'lib/browser_crawler/engine_utilities/page_inspector.rb', line 48

def before_page_scan; end

#save_to_report(screenshot_operator: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/browser_crawler/engine_utilities/page_inspector.rb', line 36

def save_to_report(screenshot_operator: nil)
  screenshot_path = save_screenshot(screenshot_operator)

  report_store.record_page_visit(
    page: link_inspector.full_url,
    extracted_links: scan_result,
    screenshot_filename: screenshot_path,
    external: link_inspector.external_url?,
    code: capybara_session.status_code
  )
end

#visit_pageObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/browser_crawler/engine_utilities/page_inspector.rb', line 25

def visit_page
  uri = link_inspector.uri
  Capybara.app_host = "#{uri.scheme}://#{uri.host}:#{uri.port}"

  visit link_inspector.full_url

  with_hooks_for(type: :each) do
    @scan_result = scanning
  end
end