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.


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

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

Class Method Details

.backendObject


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

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


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

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