Class: TmxParser::SaxDocument
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- TmxParser::SaxDocument
- Includes:
- TagNames
- Defined in:
- lib/tmx-parser/sax_document.rb
Constant Summary
Constants included from TagNames
TagNames::BEGIN_PAIRED_TAG, TagNames::END_PAIRED_TAG, TagNames::PLACEHOLDER_TAG, TagNames::PROPERTY_TAG, TagNames::SEGMENT_TAG, TagNames::UNIT_TAG, TagNames::VARIANT_TAG
Instance Attribute Summary collapse
-
#listener ⇒ Object
readonly
Returns the value of attribute listener.
Instance Method Summary collapse
- #characters(str) ⇒ Object
- #end_element(name) ⇒ Object
-
#initialize(listener) ⇒ SaxDocument
constructor
A new instance of SaxDocument.
- #start_element(name, attrs = []) ⇒ Object
Constructor Details
#initialize(listener) ⇒ SaxDocument
Returns a new instance of SaxDocument.
12 13 14 15 16 |
# File 'lib/tmx-parser/sax_document.rb', line 12 def initialize(listener) @listener = listener @capture_stack = [false] @text = '' end |
Instance Attribute Details
#listener ⇒ Object (readonly)
Returns the value of attribute listener.
10 11 12 |
# File 'lib/tmx-parser/sax_document.rb', line 10 def listener @listener end |
Instance Method Details
#characters(str) ⇒ Object
50 51 52 |
# File 'lib/tmx-parser/sax_document.rb', line 50 def characters(str) @text += str if @capture_stack.last end |
#end_element(name) ⇒ Object
44 45 46 47 48 |
# File 'lib/tmx-parser/sax_document.rb', line 44 def end_element(name) @capture_stack.pop send_text listener.done(name) end |
#start_element(name, attrs = []) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tmx-parser/sax_document.rb', line 18 def start_element(name, attrs = []) case name when UNIT_TAG listener.unit( get_attr('tuid', attrs), get_attr('segtype', attrs) ) when VARIANT_TAG locale = get_attr('xml:lang', attrs) listener.variant(locale) when SEGMENT_TAG capture_text when PROPERTY_TAG capture_text listener.property(get_attr('type', attrs)) when BEGIN_PAIRED_TAG capture_text listener.begin_paired_tag(get_attr('i', attrs)) when END_PAIRED_TAG capture_text listener.end_paired_tag(get_attr('i', attrs)) when PLACEHOLDER_TAG capture_text listener.placeholder(get_attr('type', attrs)) end end |