Class: SaxStream::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/sax_stream/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(collector, mappers) ⇒ Parser

Returns a new instance of Parser.

Raises:

  • (ArgumentError)


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