Class: SvgConform::Validation::NodeIdManager

Inherits:
Object
  • Object
show all
Defined in:
lib/svg_conform/validation/node_id_manager.rb

Overview

Manages node ID generation for validation contexts Wraps DocumentAnalyzer for DOM mode and handles ElementProxy for SAX mode

Instance Method Summary collapse

Constructor Details

#initialize(document = nil) ⇒ NodeIdManager

Returns a new instance of NodeIdManager.



10
11
12
13
# File 'lib/svg_conform/validation/node_id_manager.rb', line 10

def initialize(document = nil)
  @document = document
  @analyzer = nil # Lazy-loaded, only needed for DOM/remediation mode
end

Instance Method Details

#dom_mode?Boolean

Check if the manager has a document for DOM-based ID generation

Returns:

  • (Boolean)


30
31
32
# File 'lib/svg_conform/validation/node_id_manager.rb', line 30

def dom_mode?
  !@document.nil?
end

#generate_node_id(node) ⇒ Object

Generate a unique identifier for a node based on its path Uses DocumentAnalyzer for efficient forward-counting algorithm (DOM mode) For SAX mode, uses the pre-computed path from ElementProxy



18
19
20
21
22
23
24
25
26
27
# File 'lib/svg_conform/validation/node_id_manager.rb', line 18

def generate_node_id(node)
  # In SAX mode, node may be an ElementProxy with pre-computed path
  return node.path_id if node.respond_to?(:path_id)

  # Lazy-load the analyzer only when needed (DOM/remediation mode)
  @analyzer ||= DocumentAnalyzer.new(@document) if @document
  return nil unless @analyzer

  @analyzer.get_node_id(node)
end