Class: SvgConform::Validation::NodeIdManager
- Inherits:
-
Object
- Object
- SvgConform::Validation::NodeIdManager
- 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
-
#dom_mode? ⇒ Boolean
Check if the manager has a document for DOM-based ID generation.
-
#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.
-
#initialize(document = nil) ⇒ NodeIdManager
constructor
A new instance of NodeIdManager.
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
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 |