Class: Nokogiri::EncodingHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/nokogiri/encoding_handler.rb,
ext/nokogiri/xml_encoding_handler.c

Constant Summary collapse

USEFUL_ALIASES =

Popular encoding aliases not known by all iconv implementations that Nokogiri should support.

{
  # alias_name => true_name
  "NOKOGIRI-SENTINEL" => "UTF-8", # indicating the Nokogiri has installed aliases
  "Windows-31J" => "CP932", # Windows-31J is the IANA registered name of CP932.
  "UTF-8" => "UTF-8", # for JRuby tests, this is a no-op in CRuby
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ EncodingHandler

Returns a new instance of EncodingHandler.



48
49
50
# File 'lib/nokogiri/encoding_handler.rb', line 48

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Get the name of this EncodingHandler



80
81
82
# File 'ext/nokogiri/xml_encoding_handler.c', line 80

def name
  @name
end

Class Method Details

.Nokogiri::EncodingHandler.[](name) ⇒ Object

Get the encoding handler for name



19
20
21
# File 'ext/nokogiri/xml_encoding_handler.c', line 19

def [](name)
  storage.key?(name) ? new(storage[name]) : nil
end

.Nokogiri::EncodingHandler.alias(real_name, alias_name) ⇒ Object

Alias encoding handler with name real_name to name alias_name



52
53
54
# File 'ext/nokogiri/xml_encoding_handler.c', line 52

def alias(name, alias_name)
  storage[alias_name] = name
end

.Nokogiri::EncodingHandler.clear_aliases!Object

Remove all encoding aliases.



66
67
68
# File 'ext/nokogiri/xml_encoding_handler.c', line 66

def clear_aliases!
  storage.clear
end

.Nokogiri::EncodingHandler.delete(name) ⇒ Object

Delete the encoding alias named name



38
39
40
# File 'ext/nokogiri/xml_encoding_handler.c', line 38

def delete(name)
  storage.delete(name)
end

.install_default_aliasesObject



15
16
17
18
19
# File 'lib/nokogiri/encoding_handler.rb', line 15

def install_default_aliases
  USEFUL_ALIASES.each do |alias_name, name|
    EncodingHandler.alias(name, alias_name) if EncodingHandler[alias_name].nil?
  end
end