Class: Nokogiri::XML::BeforeHandler
- Inherits:
-
SAX::Document
- Object
- SAX::Document
- Nokogiri::XML::BeforeHandler
- Defined in:
- lib/nokogiri/xml/before_handler.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Method Summary collapse
- #characters(string) ⇒ Object
- #end_element(name) ⇒ Object
-
#initialize(node, original_html) ⇒ BeforeHandler
constructor
A new instance of BeforeHandler.
- #start_element(name, attrs = []) ⇒ Object
Methods inherited from SAX::Document
#cdata_block, #comment, #end_document, #error, #start_document, #warning
Constructor Details
#initialize(node, original_html) ⇒ BeforeHandler
Returns a new instance of BeforeHandler.
4 5 6 7 8 |
# File 'lib/nokogiri/xml/before_handler.rb', line 4 def initialize node, original_html @original_html = original_html @node = node @stack = [] end |
Instance Method Details
#characters(string) ⇒ Object
20 21 22 23 |
# File 'lib/nokogiri/xml/before_handler.rb', line 20 def characters string node = @stack.last node.content += string end |
#end_element(name) ⇒ Object
25 26 27 28 29 |
# File 'lib/nokogiri/xml/before_handler.rb', line 25 def end_element name return unless @original_html =~ /<#{name}/i @node.add_previous_sibling @stack.last if @stack.length == 1 @stack.pop end |
#start_element(name, attrs = []) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/nokogiri/xml/before_handler.rb', line 10 def start_element name, attrs = [] return unless @original_html =~ /<#{name}/i node = Node.new(name) Hash[*attrs].each do |k,v| node[k] = v end node.parent = @stack.last if @stack.length != 0 @stack << node end |