class RGen::Instantiator::NodebasedXMLInstantiator
Public Class Methods
new(env)
click to toggle source
Calls superclass method
RGen::Instantiator::AbstractInstantiator.new
# File lib/rgen/instantiator/nodebased_xml_instantiator.rb, line 66 def initialize(env) super @env = env @stack = [] end
set_prune_level(level)
click to toggle source
The prune level is the number of parent/children associations which is kept when the instantiator ascents the XML tree. If the level is 2, information for the node's children and the childrens' children will be available as an XMLNodeDescriptor object. If the level is 0 no pruning will take place, i.e. the whole information is kept until the end of the instantiation process. 0 is default.
# File lib/rgen/instantiator/nodebased_xml_instantiator.rb, line 19 def set_prune_level(level) @prune_level = level end
Public Instance Methods
end_element()
click to toggle source
# File lib/rgen/instantiator/nodebased_xml_instantiator.rb, line 95 def end_element node = @stack.pop on_ascent(node) prune_children(node, self.class.prune_level - 1) if self.class.prune_level > 0 end
instantiate(text)
click to toggle source
# File lib/rgen/instantiator/nodebased_xml_instantiator.rb, line 77 def instantiate(text) parse(text) resolve end
instantiate_file(file)
click to toggle source
# File lib/rgen/instantiator/nodebased_xml_instantiator.rb, line 72 def instantiate_file(file) File.open(file) { |f| parse(f.read)} resolve end
namespaces()
click to toggle source
# File lib/rgen/instantiator/nodebased_xml_instantiator.rb, line 120 def namespaces @visitor.namespaces if @visitor end
on_ascent(node)
click to toggle source
This method is called when the XML parser goes up the tree. An XMLNodeDescriptor
node
describes the current node. Implementing classes must
overwrite this method.
# File lib/rgen/instantiator/nodebased_xml_instantiator.rb, line 116 def on_ascent(node) raise "Overwrite this method !" end
on_chardata(str)
click to toggle source
# File lib/rgen/instantiator/nodebased_xml_instantiator.rb, line 101 def on_chardata(str) node = @stack.last node.chardata << str end
on_descent(node)
click to toggle source
This method is called when the XML parser goes down the tree. An XMLNodeDescriptor
node
describes the current node. Implementing classes must
overwrite this method.
# File lib/rgen/instantiator/nodebased_xml_instantiator.rb, line 109 def on_descent(node) raise "Overwrite this method !" end
parse(src)
click to toggle source
# File lib/rgen/instantiator/nodebased_xml_instantiator.rb, line 82 def parse(src) @visitor = Visitor.new(self) parser = Nokogiri::XML::SAX::Parser.new(@visitor) parser.parse(src) @visitor = nil end
start_element(ns, qtag, prefix, tag, attributes)
click to toggle source
# File lib/rgen/instantiator/nodebased_xml_instantiator.rb, line 89 def start_element(ns, qtag, prefix, tag, attributes) node = XMLNodeDescriptor.new(ns, qtag, prefix, tag, @stack[-1], [], attributes) @stack.push node on_descent(node) end
Private Instance Methods
prune_children(node, level)
click to toggle source
# File lib/rgen/instantiator/nodebased_xml_instantiator.rb, line 126 def prune_children(node, level) if level == 0 node.children = nil else node.children.each { |c| prune_children(c, level-1) } end end