Class: EmuPower::StreamParser
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- EmuPower::StreamParser
- Defined in:
- lib/emu_power/stream_parser.rb
Defined Under Namespace
Classes: Parser
Constant Summary collapse
- FAKEROOT =
'FAKEROOT'
Instance Method Summary collapse
-
#initialize(io, line_terminator, roots, &block) ⇒ StreamParser
constructor
A new instance of StreamParser.
-
#parse ⇒ Object
Push all new lines from the io into the parser.
Constructor Details
#initialize(io, line_terminator, roots, &block) ⇒ StreamParser
Returns a new instance of StreamParser.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/emu_power/stream_parser.rb', line 10 def initialize(io, line_terminator, roots, &block) @line_terminator = line_terminator @io = io # Use a push parser so we can fake a single root element @parser = Nokogiri::XML::SAX::PushParser.new(Parser.new(FAKEROOT, roots, &block)) # This is the "root" of the document. We intentionally never close this # so that the parser doesn't get mad when it encounters multiple real # root elements. @parser << "<#{FAKEROOT}>" end |
Instance Method Details
#parse ⇒ Object
Push all new lines from the io into the parser. The parser will fire the callback given on construction once a whole object has been processed.
28 29 30 31 |
# File 'lib/emu_power/stream_parser.rb', line 28 def parse lines = @io.readlines(@line_terminator) lines.each { |l| @parser << l } end |