Class: SXRB::Proxy
- Inherits:
-
Object
- Object
- SXRB::Proxy
- Defined in:
- lib/sxrb/proxy.rb
Overview
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.
Instance Method Summary collapse
-
#child(*tags) {|Proxy| ... } ⇒ nil
Defines child (a direct descendant) of an element defined in current block.
-
#descendant(*tags) {|Proxy| ... } ⇒ nil
Defines descendant of an element defined in current block.
-
#initialize(callback_tree, current_path = '') ⇒ Proxy
constructor
private
Proxy objects are generated by the SXRB itself, and are passed to blocks to be used as DSL.
-
#on_characters {|String| ... } ⇒ nil
Defines a callback that is invoked whenever anonymous text node within self is encountered.
-
#on_element {|Node| ... } ⇒ nil
Defines callback method invoked when matching element is completely parsed.
-
#on_end {|Node| ... } ⇒ nil
Defines a callback that is invoked whenever end tag is encountered.
-
#on_start {|Node| ... } ⇒ nil
Defines a callback that is invoked whenever start tag is encountered.
Constructor Details
#initialize(callback_tree, current_path = '') ⇒ Proxy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
12 13 14 15 |
# File 'lib/sxrb/proxy.rb', line 12 def initialize(callback_tree, current_path = '') @callback_tree = callback_tree @current_path = current_path end |
Instance Method Details
#child(*tags) {|Proxy| ... } ⇒ nil
Add Regexp and other selectors support in addition to Strings.
Defines child (a direct descendant) of an element defined in current block.
29 30 31 32 33 34 35 |
# File 'lib/sxrb/proxy.rb', line 29 def child(*, &block) .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 |
#descendant(*tags) {|Proxy| ... } ⇒ nil
Add Regexp and other selectors support in addition to strings.
Defines descendant of an element defined in current block.
49 50 51 52 53 54 55 |
# File 'lib/sxrb/proxy.rb', line 49 def descendant(*, &block) .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 |
#on_characters {|String| ... } ⇒ nil
Defines a callback that is invoked whenever anonymous text node within self is encountered.
95 96 97 |
# File 'lib/sxrb/proxy.rb', line 95 def on_characters(&block) @callback_tree.add_callback(:characters, @current_path, &block) end |
#on_element {|Node| ... } ⇒ nil
‘on_element` should not be used for items that are expected to have large node subtrees.
Defines callback method invoked when matching element is completely parsed.
70 71 72 |
# File 'lib/sxrb/proxy.rb', line 70 def on_element(&block) @callback_tree.add_callback(:element, @current_path, &block) end |
#on_end {|Node| ... } ⇒ nil
Defines a callback that is invoked whenever end tag is encountered.
107 108 109 |
# File 'lib/sxrb/proxy.rb', line 107 def on_end(&block) @callback_tree.add_callback(:end, @current_path, &block) end |
#on_start {|Node| ... } ⇒ nil
Defines a callback that is invoked whenever start tag is encountered.
82 83 84 |
# File 'lib/sxrb/proxy.rb', line 82 def on_start(&block) @callback_tree.add_callback(:start, @current_path, &block) end |