Class: Plaintext::ZippedXmlHandler::SaxDocument
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Plaintext::ZippedXmlHandler::SaxDocument
- Defined in:
- lib/plaintext/file_handler/zipped_xml_handler.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#characters(string) ⇒ Object
Any characters between the start and end element expected as a string.
-
#end_element_namespace(name, prefix = nil, uri = nil) ⇒ Object
Given the name of an element once its closing tag is reached.
-
#initialize(text_element, text_namespace, max_size = nil) ⇒ SaxDocument
constructor
A new instance of SaxDocument.
-
#start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = []) ⇒ Object
Handle each element, expecting the name and any attributes.
- #text_length_exceeded? ⇒ Boolean
Constructor Details
#initialize(text_element, text_namespace, max_size = nil) ⇒ SaxDocument
Returns a new instance of SaxDocument.
12 13 14 15 16 17 18 19 |
# File 'lib/plaintext/file_handler/zipped_xml_handler.rb', line 12 def initialize(text_element, text_namespace, max_size = nil) @element = text_element @namespace_uri = text_namespace @max_size = max_size @text = ''.dup @is_text = false end |
Instance Attribute Details
#text ⇒ Object (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
37 38 39 |
# File 'lib/plaintext/file_handler/zipped_xml_handler.rb', line 37 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
42 43 44 45 46 47 48 49 50 |
# File 'lib/plaintext/file_handler/zipped_xml_handler.rb', line 42 def end_element_namespace(name, prefix = nil, uri = nil) if name == @element and uri == @namespace_uri and @is_text @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
27 28 29 30 31 32 33 34 |
# File 'lib/plaintext/file_handler/zipped_xml_handler.rb', line 27 def start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = []) if name == @element and uri == @namespace_uri and !text_length_exceeded? @is_text = true end end |
#text_length_exceeded? ⇒ Boolean
21 22 23 |
# File 'lib/plaintext/file_handler/zipped_xml_handler.rb', line 21 def text_length_exceeded? @max_size && (@text.length > @max_size) end |