Class: Nous::Fetcher::PageExtractor

Inherits:
Command
  • Object
show all
Defined in:
lib/nous/fetcher/page_extractor.rb

Instance Method Summary collapse

Methods inherited from Command

call, #failure, #success

Constructor Details

#initialize(extractor:, record:) ⇒ PageExtractor

Returns a new instance of PageExtractor.



6
7
8
9
# File 'lib/nous/fetcher/page_extractor.rb', line 6

def initialize(extractor:, record:)
  @extractor = extractor
  @record = record
end

Instance Method Details

#call ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nous/fetcher/page_extractor.rb', line 11

def call
  result = extractor.extract(record)

  unless result.success?
    warn("[nous] extract skip #{record.final_url}: #{result.error.message}") if Nous.configuration.debug?
    return failure(result.error)
  end

  page = Page.new(
    title: result.payload.title,
    url: record.final_url,
    pathname: record.pathname,
    content: result.payload.content,
    metadata: {
      extractor: extractor.class.name,
      requested_url: record.requested_url,
      content_type: record.content_type,
      redirected: record.redirected
    }
  )

  success(payload: page)
end