Class: Moxml::Adapter::Leptris::SaxRecordReplay
- Inherits:
-
Object
- Object
- Moxml::Adapter::Leptris::SaxRecordReplay
- Defined in:
- lib/moxml/adapter/leptris/sax_record_replay.rb
Overview
Replays the engine's bulk SAX record table (leptris#1298) to the bridge protocol. One drain crossing replaces the per-event recorder replay; the only String materializations left are the name/value/text data the handler actually consumes. End events reconstruct from the records' parent indices with a name-carrying stack — pre-order records make a parent mismatch the exact close boundary, and self-closing elements pop at their next sibling, matching the callback engine's event stream.
Constant Summary collapse
- KIND_ELEMENT =
::Leptris::XML::SAX::Records::KIND_ELEMENT
Instance Method Summary collapse
-
#initialize(bridge) ⇒ SaxRecordReplay
constructor
A new instance of SaxRecordReplay.
- #run(table) ⇒ Object
Constructor Details
#initialize(bridge) ⇒ SaxRecordReplay
Returns a new instance of SaxRecordReplay.
20 21 22 |
# File 'lib/moxml/adapter/leptris/sax_record_replay.rb', line 20 def initialize(bridge) @bridge = bridge end |
Instance Method Details
#run(table) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/moxml/adapter/leptris/sax_record_replay.rb', line 24 def run(table) @bridge.start_document idx_stack = [] name_stack = [] count = table.count i = 0 while i < count while !idx_stack.empty? && table.parent(i) != idx_stack.last idx_stack.pop @bridge.end_element(name_stack.pop) end if table.kind(i) == KIND_ELEMENT name = table.view(i) pairs = [] k = table.attr_first(i) last = k + table.attr_count_of(i) while k < last v = table.attr_value(k) pairs << [table.attr_name(k), table.attr_value_has_ws?(k) ? v.tr("\t\n\r", " ") : v] k += 1 end @bridge.start_element(name, pairs) idx_stack << i name_stack << name else @bridge.characters(table.view(i)) end i += 1 end @bridge.end_element(name_stack.pop) until name_stack.empty? @bridge.end_document end |