Class: Nokogiri::HTML::Document::EncodingReader::SAXHandler

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

Overview

:nodoc:

Direct Known Subclasses

JumpSAXHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSAXHandler

Returns a new instance of SAXHandler.



223
224
225
226
# File 'lib/nokogiri/html/document.rb', line 223

def initialize
  @encoding = nil
  super()
end

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



221
222
223
# File 'lib/nokogiri/html/document.rb', line 221

def encoding
  @encoding
end

Instance Method Details

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



228
229
230
231
232
233
234
235
236
237
238
# File 'lib/nokogiri/html/document.rb', line 228

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