Class: Nokogiri::HTML::SAX::PushParser

Inherits:
NokogiriXmlSaxPushParser
  • Object
show all
Defined in:
lib/nokogiri/html/sax/push_parser.rb,
ext/nokogiri/html_sax_push_parser.c

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc = HTML::SAX::Document.new, file_name = nil, encoding = 'UTF-8') ⇒ PushParser

Returns a new instance of PushParser.



10
11
12
13
14
15
16
17
# File 'lib/nokogiri/html/sax/push_parser.rb', line 10

def initialize(doc = HTML::SAX::Document.new, file_name = nil, encoding = 'UTF-8')
  @document = doc
  @encoding = encoding
  @sax_parser = HTML::SAX::Parser.new(doc, @encoding)

  ## Create our push parser context
  initialize_native(@sax_parser, file_name, encoding)
end

Instance Attribute Details

#documentObject

The Nokogiri::HTML::SAX::Document on which the PushParser will be operating



8
9
10
# File 'lib/nokogiri/html/sax/push_parser.rb', line 8

def document
  @document
end

Instance Method Details

#finishObject

Finish the parsing. This method is only necessary for Nokogiri::HTML::SAX::Document#end_document to be called.



30
31
32
# File 'lib/nokogiri/html/sax/push_parser.rb', line 30

def finish
  write '', true
end

#write(chunk, last_chunk = false) ⇒ Object Also known as: <<

Write a chunk of HTML to the PushParser. Any callback methods that can be called will be called immediately.



22
23
24
# File 'lib/nokogiri/html/sax/push_parser.rb', line 22

def write chunk, last_chunk = false
  native_write(chunk, last_chunk)
end