Class: SaxStream::Parser
- Inherits:
-
Object
- Object
- SaxStream::Parser
- Defined in:
- lib/sax_stream/parser.rb
Instance Method Summary collapse
-
#initialize(collector, mappers) ⇒ Parser
constructor
A new instance of Parser.
- #parse_stream(io_stream, encoding = 'UTF-8') ⇒ Object
Constructor Details
#initialize(collector, mappers) ⇒ Parser
Returns a new instance of Parser.
7 8 9 10 11 |
# File 'lib/sax_stream/parser.rb', line 7 def initialize(collector, mappers) raise ArgumentError, "You must supply your parser with a collector" unless collector raise ArgumentError, "You must supply your parser with at least one mapper class" if mappers.empty? @sax_handler = Internal::SaxHandler.new(collector, mappers) end |
Instance Method Details
#parse_stream(io_stream, encoding = 'UTF-8') ⇒ Object
13 14 15 16 |
# File 'lib/sax_stream/parser.rb', line 13 def parse_stream(io_stream, encoding = 'UTF-8') parser = Nokogiri::XML::SAX::Parser.new(@sax_handler) parser.parse_io(io_stream, encoding) end |