Class: Browserctl::SnapshotBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/browserctl/server/snapshot_builder.rb

Overview

Orchestrates the snapshot pipeline:

page.body  ──Extractor──▶  [nodes]
           ──Annotator──▶  [entries with ref + fingerprint]
           ──Serializer─▶  wire-shape array

Each stage is independently testable. Inject alternates via the keyword args for tests that want to isolate one stage.

Instance Method Summary collapse

Constructor Details

#initialize(extractor: Snapshot::Extractor.new, annotator: Snapshot::Annotator.new, serializer: Snapshot::Serializer.new) ⇒ SnapshotBuilder

Returns a new instance of SnapshotBuilder.



17
18
19
20
21
22
23
# File 'lib/browserctl/server/snapshot_builder.rb', line 17

def initialize(extractor: Snapshot::Extractor.new,
               annotator: Snapshot::Annotator.new,
               serializer: Snapshot::Serializer.new)
  @extractor = extractor
  @annotator = annotator
  @serializer = serializer
end

Instance Method Details

#call(page) ⇒ Object



25
26
27
28
29
# File 'lib/browserctl/server/snapshot_builder.rb', line 25

def call(page)
  nodes = @extractor.call(page.body)
  entries = @annotator.call(nodes)
  @serializer.call(entries)
end