Class: Nokogiri::HTML4::Document::EncodingReader::SAXHandler

Inherits:
XML::SAX::Document show all
Defined in:
lib/nokogiri/html4/document.rb

Overview

:nodoc:

Since:

  • v1.12.0

Direct Known Subclasses

JumpSAXHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from XML::SAX::Document

#cdata_block, #characters, #comment, #end_document, #end_element, #end_element_namespace, #error, #processing_instruction, #start_document, #start_element_namespace, #warning, #xmldecl

Constructor Details

#initializeSAXHandler

Returns a new instance of SAXHandler.

Since:

  • v1.12.0



232
233
234
235
# File 'lib/nokogiri/html4/document.rb', line 232

def initialize
  @encoding = nil
  super()
end

Instance Attribute Details

#encodingObject (readonly)

Since:

  • v1.12.0



230
231
232
# File 'lib/nokogiri/html4/document.rb', line 230

def encoding
  @encoding
end

Instance Method Details

#start_element(name, attrs = []) ⇒ Object

Since:

  • v1.12.0



237
238
239
240
241
242
243
244
245
246
247
# File 'lib/nokogiri/html4/document.rb', line 237

def start_element(name, attrs = [])
  return unless name == 'meta'
  attr = Hash[attrs]
  charset = attr['charset'] and
    @encoding = charset
  http_equiv = attr['http-equiv'] and
    http_equiv.match(/\AContent-Type\z/i) and
    content = attr['content'] and
    m = content.match(/;\s*charset\s*=\s*([\w-]+)/) and
    @encoding = m[1]
end