Class: SXRB::Parser

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

Instance Method Summary collapse

Constructor Details

#initialize(input, opts = {}, &block) ⇒ Parser

Returns a new instance of Parser.

Raises:

  • (ArgumentError)

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sxrb/parser.rb', line 6

def initialize(input, opts = {}, &block)
  raise ArgumentError.new("Block expected") if block.nil?
  options = {:mode => :string}.merge(opts)

  # Create parser according to options

  parser = case options[:mode]
           when :string
             LibXML::XML::SaxParser.string(input)
           end

  callbacks = Callbacks.new.tap do |cb|
    yield Proxy.new(cb)
  end

  parser.callbacks = callbacks
  parser.parse
end