Class: Browserctl::Snapshot::Annotator

Inherits:
Object
  • Object
show all
Defined in:
lib/browserctl/snapshot/annotator.rb

Overview

Stage 2 of the snapshot pipeline.

Takes the list of interactable nodes from Extractor and produces element entries with stable refs, semantic metadata, a CSS selector path, and a fingerprint. Each entry is a plain Hash.

Constant Summary collapse

ATTRS =
%w[type name placeholder href aria-label role].freeze

Instance Method Summary collapse

Constructor Details

#initialize(ref_deriver: RefDeriver.new, fingerprint: Fingerprint.new) ⇒ Annotator

Returns a new instance of Annotator.



16
17
18
19
# File 'lib/browserctl/snapshot/annotator.rb', line 16

def initialize(ref_deriver: RefDeriver.new, fingerprint: Fingerprint.new)
  @ref_deriver = ref_deriver
  @fingerprint = fingerprint
end

Instance Method Details

#call(nodes) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/browserctl/snapshot/annotator.rb', line 21

def call(nodes)
  taken = {}
  nodes.map do |node|
    ref = @ref_deriver.disambiguate(@ref_deriver.derive(node), taken)
    taken[ref] = true
    entry(node, ref)
  end
end