class SXRB::Proxy
Objects of Proxy
class are part of SXRB
DSL and their methods are meant to be used to define set of rules needed to parse XML document. They have no other meaning and should not be used outside of that scope. @api public
Public Class Methods
Proxy
objects are generated by the SXRB
itself, and are passed to blocks to be used as DSL. They should not be created in any other context. Implementation might change without prior notice.
@api private
# File lib/sxrb/proxy.rb, line 12 def initialize(callback_tree, current_path = '') @callback_tree = callback_tree @current_path = current_path end
Public Instance Methods
Defines child (a direct descendant) of an element defined in current block. @param [String] tags
names of tags that should be matched
@yield [Proxy]
block receives Proxy element representing matched elements.
@return [nil]
@api public
@todo Add Regexp and other selectors support in addition to Strings.
# File lib/sxrb/proxy.rb, line 29 def child(*tags, &block) tags.each do |tag| @callback_tree.add_rule(tag, @current_path, :recursive => false).tap do |new_path| block.call(Proxy.new(@callback_tree, new_path)) end end end
Defines descendant of an element defined in current block. @param [String] tags
names of tags that should be matched
@yield [Proxy]
block receives Proxy element representing matched elements.
@return [nil]
@api public
@todo Add Regexp and other selectors support in addition to strings.
# File lib/sxrb/proxy.rb, line 49 def descendant(*tags, &block) tags.each do |tag| @callback_tree.add_rule(tag, @current_path, :recursive => true).tap do |new_path| block.call(Proxy.new(@callback_tree, new_path)) end end end
Defines a callback that is invoked whenever anonymous text node within self is encountered.
@yield [String]
block receives raw content of parsed data in form of string object.
@return [nil]
@api public
# File lib/sxrb/proxy.rb, line 95 def on_characters(&block) @callback_tree.add_callback(:characters, @current_path, &block) end
Defines callback method invoked when matching element is completely parsed.
@yield [Node]
block receives whole parsed element with children.
@api public
@return [nil]
@note
`on_element` should not be used for items that are expected to have large node subtrees.
# File lib/sxrb/proxy.rb, line 70 def on_element(&block) @callback_tree.add_callback(:element, @current_path, &block) end
Defines a callback that is invoked whenever end tag is encountered.
@yield [Node]
block receives parsed node without any nested elements. All inline attributes are available though.
@return [nil] @api public
# File lib/sxrb/proxy.rb, line 107 def on_end(&block) @callback_tree.add_callback(:end, @current_path, &block) end
Defines a callback that is invoked whenever start tag is encountered.
@yield [Node]
block receives parsed node without any nested elements. All inline attributes are available though.
@return [nil] @api public
# File lib/sxrb/proxy.rb, line 82 def on_start(&block) @callback_tree.add_callback(:start, @current_path, &block) end