Class: ChupaText::SAXParser::Document

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/chupa-text/sax-parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(listener) ⇒ Document

Returns a new instance of Document.


59
60
61
62
# File 'lib/chupa-text/sax-parser.rb', line 59

def initialize(listener)
  @listener = listener
  @namespaces_stack = []
end

Instance Method Details

#cdata_block(content) ⇒ Object


96
97
98
# File 'lib/chupa-text/sax-parser.rb', line 96

def cdata_block(content)
  @listener.cdata(content)
end

#characters(text) ⇒ Object


92
93
94
# File 'lib/chupa-text/sax-parser.rb', line 92

def characters(text)
  @listener.characters(text)
end

#end_element_namespace(name, prefix = nil, uri = nil) ⇒ Object


84
85
86
87
88
89
90
# File 'lib/chupa-text/sax-parser.rb', line 84

def end_element_namespace(name, prefix=nil, uri=nil)
  @listener.end_element(uri, name, build_qname(prefix, name))
  namespaces = @namespaces_stack.pop
  namespaces.each do |namespace_prefix, _|
    @listener.end_prefix_mapping(namespace_prefix)
  end
end

#error(detail) ⇒ Object

Raises:


100
101
102
# File 'lib/chupa-text/sax-parser.rb', line 100

def error(detail)
  raise ParseError, detail
end

#start_element_namespace(name, attributes = [], prefix = nil, uri = nil, namespaces = []) ⇒ Object


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/chupa-text/sax-parser.rb', line 64

def start_element_namespace(name,
                            attributes=[],
                            prefix=nil,
                            uri=nil,
                            namespaces=[])
  namespaces.each do |namespace_prefix, namespace_uri|
    @listener.start_prefix_mapping(namespace_prefix, namespace_uri)
  end
  attributes_hash = {}
  attributes.each do |attribute|
    attribute_qname = build_qname(attribute.prefix, attribute.localname)
    attributes_hash[attribute_qname] = attribute.value
  end
  @namespaces_stack.push(namespaces)
  @listener.start_element(uri,
                          name,
                          build_qname(prefix, name),
                          attributes_hash)
end