Class: Nokogiri::HTML::Document::EncodingReader::SAXHandler
- Inherits:
-
XML::SAX::Document
- Object
- XML::SAX::Document
- Nokogiri::HTML::Document::EncodingReader::SAXHandler
- Defined in:
- lib/nokogiri/html/document.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
Instance Method Summary collapse
-
#initialize ⇒ SAXHandler
constructor
A new instance of SAXHandler.
- #start_element(name, attrs = []) ⇒ Object
Methods inherited from XML::SAX::Document
#cdata_block, #characters, #comment, #end_document, #end_element, #end_element_namespace, #error, #start_document, #start_element_namespace, #warning, #xmldecl
Constructor Details
#initialize ⇒ SAXHandler
Returns a new instance of SAXHandler.
141 142 143 144 |
# File 'lib/nokogiri/html/document.rb', line 141 def initialize @encoding = nil super() end |
Instance Attribute Details
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
139 140 141 |
# File 'lib/nokogiri/html/document.rb', line 139 def encoding @encoding end |
Instance Method Details
#start_element(name, attrs = []) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/nokogiri/html/document.rb', line 146 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 |