Class: SvgConform::DocumentAnalyzer
- Inherits:
-
Object
- Object
- SvgConform::DocumentAnalyzer
- Defined in:
- lib/svg_conform/document_analyzer.rb
Overview
Document analyzer that computes node IDs using forward counting to avoid expensive backward sibling traversal.
Uses parent.children iteration to calculate position among siblings, which is more efficient than walking previous_sibling chain.
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
Instance Method Summary collapse
-
#get_node_id(node) ⇒ Object
Get path-based ID for a node from cache.
-
#initialize(document) ⇒ DocumentAnalyzer
constructor
A new instance of DocumentAnalyzer.
Constructor Details
#initialize(document) ⇒ DocumentAnalyzer
Returns a new instance of DocumentAnalyzer.
12 13 14 15 16 |
# File 'lib/svg_conform/document_analyzer.rb', line 12 def initialize(document) @document = document @cache = {} populate_cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
10 11 12 |
# File 'lib/svg_conform/document_analyzer.rb', line 10 def cache @cache end |
Instance Method Details
#get_node_id(node) ⇒ Object
Get path-based ID for a node from cache
19 20 21 22 23 24 25 26 |
# File 'lib/svg_conform/document_analyzer.rb', line 19 def get_node_id(node) return nil unless node.respond_to?(:name) && node.name # Use native.object_id as cache key since wrapper object_id changes # across traverses but underlying Nokogiri node identity is stable native_id = node.native.object_id @cache[native_id] ||= compute_and_cache_path(node) end |