Class: XML::Digester::BlockRule

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

Overview

Rule that executes the given block when matched. The supplied block should have a variable argument count, since it is used with different arguments by the different events, as follows:

begin : { |:begin, digester, namespace, name, attrs| ... }
body  : { |:body, digester, txt| ... }
end   : { |:end, digester, namespace, name| ... }
finish: { |:finish| ... }

Instance Attribute Summary

Attributes inherited from RulesBase

#digester, #next, #pattern, #prev

Instance Method Summary collapse

Constructor Details

#initialize(pattern, &blk) ⇒ BlockRule

call-seq:

BlockRule.new(pattern) { |*args| ... }

Create a new BlockRule with the supplied block.



78
79
80
81
# File 'lib/xml/digestr.rb', line 78

def initialize(pattern, &blk)
  super(pattern)
  @blk = blk or raise ArgumentError, "No block given"
end

Instance Method Details

#begin(namespace, name, attrs) ⇒ Object

:nodoc:



83
84
85
# File 'lib/xml/digestr.rb', line 83

def begin(namespace, name, attrs) #:nodoc:
  @blk.call(:begin, @digester, namespace, name, attrs)
end

#body(txt) ⇒ Object

:nodoc:



87
88
89
# File 'lib/xml/digestr.rb', line 87

def body(txt) #:nodoc:
  @blk.call(:body, @digester, txt)
end

#end(namespace, name) ⇒ Object

:nodoc:



91
92
93
# File 'lib/xml/digestr.rb', line 91

def end(namespace, name) #:nodoc:
  @blk.call(:end, @digester, namespace, name)
end

#finishObject

:nodoc:



95
96
97
# File 'lib/xml/digestr.rb', line 95

def finish #:nodoc:
  @blk.call(:finish)
end