Class: XML::Digester::SetTopRule

Inherits:
LinkRule show all
Defined in:
lib/xml/digestr.rb

Overview

Rule that allows a child -> parent relationship to be created between the top two stack elements via a given method call. This is a specialized LinkRule that calls a method on the top stack element, passing in the next-to-top element as an argument. Often, the called method will have a name like ‘set_parent’.

Like LinkRule, this rule operates in the end event. See also SetNextRule.

Instance Attribute Summary

Attributes inherited from RulesBase

#digester, #next, #pattern, #prev

Instance Method Summary collapse

Methods inherited from LinkRule

#end

Methods inherited from RulesBase

#begin, #body, #end, #finish

Constructor Details

#initialize(pattern, msg, *args) ⇒ SetTopRule

call-seq:

SetTopRule.new(pattern, msg, *additional_args)

Create a new SetTopRule that will send the specified message to the top stack object, passing in the next-to-top object as the initial parameter, followed by any additional arguments supplied to this method.



359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/xml/digestr.rb', line 359

def initialize(pattern, msg, *args)
  super(pattern) do |parent, child|
    begin
      child.send(msg, parent, *args)
    rescue NoMethodError
      if digester.pedantic?
        raise Error,
            "Cannot SetTop: no method #{msg} for #{parent.inspect}"
        nil
      end
    end
  end
end