Class: Plaintext::ZippedXmlHandler::SaxDocument

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/plaintext/file_handler/zipped_xml_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text_element, text_namespace) ⇒ SaxDocument

Returns a new instance of SaxDocument.



12
13
14
15
16
17
# File 'lib/plaintext/file_handler/zipped_xml_handler.rb', line 12

def initialize(text_element, text_namespace)
  @element = text_element
  @namespace_uri = text_namespace
  @text = ''.dup
  @is_text = false
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



10
11
12
# File 'lib/plaintext/file_handler/zipped_xml_handler.rb', line 10

def text
  @text
end

Instance Method Details

#characters(string) ⇒ Object

Any characters between the start and end element expected as a string



27
28
29
# File 'lib/plaintext/file_handler/zipped_xml_handler.rb', line 27

def characters(string)
  @text << string if @is_text
end

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

Given the name of an element once its closing tag is reached



32
33
34
35
36
37
# File 'lib/plaintext/file_handler/zipped_xml_handler.rb', line 32

def end_element_namespace(name, prefix = nil, uri = nil)
  if name == @element and uri == @namespace_uri
    @text << ' '
    @is_text = false
  end
end

#start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = []) ⇒ Object

Handle each element, expecting the name and any attributes



20
21
22
23
24
# File 'lib/plaintext/file_handler/zipped_xml_handler.rb', line 20

def start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = [])
  if name == @element and uri == @namespace_uri
    @is_text = true
  end
end