Class: ChupaText::SAXParser

Inherits:
Object
  • Object
show all
Defined in:
lib/chupa-text/sax-parser.rb

Defined Under Namespace

Classes: Document, Listener, ParseError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, listener) ⇒ SAXParser

Returns a new instance of SAXParser.



47
48
49
50
# File 'lib/chupa-text/sax-parser.rb', line 47

def initialize(input, listener)
  @input = input
  @listener = listener
end

Class Method Details

.backendObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/chupa-text/sax-parser.rb', line 33

def backend
  case ENV["CHUPA_TEXT_SAX_PARSER_BACKEND"]
  when "rexml"
    :rexml
  else
    if Object.const_defined?(:Nokogiri)
      :nokogiri
    else
      :rexml
    end
  end
end

Instance Method Details

#parseObject



53
54
55
56
57
# File 'lib/chupa-text/sax-parser.rb', line 53

def parse
  document = Document.new(@listener)
  parser = Nokogiri::XML::SAX::Parser.new(document)
  parser.parse(@input)
end