Class: Nori::Parser::Nokogiri::Document

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/nori/parser/nokogiri.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options


12
13
14
# File 'lib/nori/parser/nokogiri.rb', line 12

def options
  @options
end

Instance Method Details

#characters(string) ⇒ Object Also known as: cdata_block

If this node is a successive character then add it as is. First child being a space-only text node will not be added because there is no previous characters.


38
39
40
41
42
43
# File 'lib/nori/parser/nokogiri.rb', line 38

def characters(string)
  last = stack.last
  if last and last.children.last.is_a?(String) or string.strip.size > 0
    last.add_node(string)
  end
end

#end_element(name) ⇒ Object

To keep backward behaviour compatibility delete last child if it is a space-only text node


24
25
26
27
28
29
30
31
32
33
# File 'lib/nori/parser/nokogiri.rb', line 24

def end_element(name)
  if stack.size > 1
    last = stack.pop
    maybe_string = last.children.last
    if maybe_string.is_a?(String) and maybe_string.strip.empty?
      last.children.pop
    end
    stack.last.add_node last
  end
end

#stackObject


14
15
16
# File 'lib/nori/parser/nokogiri.rb', line 14

def stack
  @stack ||= []
end

#start_element(name, attrs = []) ⇒ Object


18
19
20
# File 'lib/nori/parser/nokogiri.rb', line 18

def start_element(name, attrs = [])
  stack.push Nori::XMLUtilityNode.new(options, name, Hash[*attrs.flatten])
end