Class: SvgConform::NodeIndexBuilder

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

Overview

Builds an index of node positions in single forward pass Replicates the exact logic of backward sibling traversal but computed forward

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ NodeIndexBuilder

Returns a new instance of NodeIndexBuilder.



7
8
9
10
# File 'lib/svg_conform/node_index_builder.rb', line 7

def initialize(document)
  @node_positions = {}
  build_index(document.root) if document.root
end

Instance Method Details

#get_position(node) ⇒ Object

Get position of node among its siblings with same name



13
14
15
# File 'lib/svg_conform/node_index_builder.rb', line 13

def get_position(node)
  @node_positions[node]
end