| Class | YAML::Transformer |
| In: |
lib/yaml_extensions/transform.rb
|
| Parent: | Object |
Constructor.
# File lib/yaml_extensions/transform.rb, line 207 def initialize @rootgraph = Root.new @graph = [] @activated = [] end
Work like XLST. Traverse all tree and return a list of element that match the path.
# File lib/yaml_extensions/transform.rb, line 289 def self.traverse ( path, tree, &block ) p = self.new p.add(path, &block) p.traverse(tree) end
Register the given block and compile the path.
# File lib/yaml_extensions/transform.rb, line 214 def add ( path, name=nil, &block) raise ArgumentError unless (path.kind_of?(YRegexPath)) raise ArgumentError if (block.nil?) current_nodes = path.root ? @rootgraph.children : @graph add_segment(path.segments, path.wanted_node_index, current_nodes, name, &block) end
Print graph in a file in doty format
# File lib/yaml_extensions/transform.rb, line 253 def dottify ( filename ) File.open(filename, 'w') do |f| f << "/* Compiled rules graph visualisation by YSLT */\ndigraph \"Compiled rules\" {\nnode [style=filled]\nedge [style=solid, arrowtail=none]\nrankdir=LR\n" @rootgraph.dottify(f) @graph.each do |n| n.dottify(f) end f << "}\n" end end
Reset position to root.
# File lib/yaml_extensions/transform.rb, line 272 def reset @activated = @rootgraph.children + @graph end