Class: FetchUtil::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/fetch_util/extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(reader_mode: true, asset_root: nil) ⇒ Extractor

Returns a new instance of Extractor.



7
8
9
10
# File 'lib/fetch_util/extractor.rb', line 7

def initialize(reader_mode: true, asset_root: nil)
  @reader_mode = reader_mode
  @asset_root = asset_root || File.join(__dir__, "assets")
end

Instance Method Details

#extract(page) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/fetch_util/extractor.rb', line 12

def extract(page)
  payload = extract_payload(page)
  raise ExtractionError, "Page extraction returned no content" unless payload.is_a?(Hash)

  payload
rescue Ferrum::JavaScriptError, Ferrum::StatusError, Ferrum::TimeoutError => e
  raise ExtractionError, e.message
end