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

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

Instance Method Summary collapse

Instance Method Details

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



28
29
30
# File 'lib/nori/parser/nokogiri.rb', line 28

def characters(string)
  stack.last.add_node(string) unless string.strip.length == 0 || stack.empty?
end

#end_element(name) ⇒ Object



21
22
23
24
25
26
# File 'lib/nori/parser/nokogiri.rb', line 21

def end_element(name)
  if stack.size > 1
    last = stack.pop
    stack.last.add_node last
  end
end

#stackObject



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

def stack
  @stack ||= []
end

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



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

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