Class YAML::Transformer
In: lib/yaml_extensions/transform.rb
Parent: Object

Methods

add   clear   dottify   new   register   reset   traverse   traverse   update_node  

Classes and Modules

Class YAML::Transformer::Match
Class YAML::Transformer::Node
Class YAML::Transformer::Root

Public Class methods

Constructor.

[Source]

# 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.

[Source]

# 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

Public Instance methods

Register the given block and compile the path.

[Source]

# 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

Clear compiled rules.

[Source]

# File lib/yaml_extensions/transform.rb, line 277
    def clear
      initialize
    end

Print graph in a file in doty format

[Source]

# 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
register( path, name=nil, &block)

Alias for add

Reset position to root.

[Source]

# File lib/yaml_extensions/transform.rb, line 272
    def reset
      @activated = @rootgraph.children + @graph
    end

Traverse an entire YAML tree.

[Source]

# File lib/yaml_extensions/transform.rb, line 282
    def traverse ( tree )
      reset
      tree.yaml_doc_traverse(@activated)
    end

[Source]

# File lib/yaml_extensions/transform.rb, line 246
    def update_node ( node, value, segment, remember_index, name, &block )
      sons = node.get_associated(value, remember_index == 1)
      add_segment(segment, remember_index - 1, sons, name, &block)
      return node
    end

[Validate]