Class: HTMLEntities::Decoder

Inherits:
Object
  • Object
show all
Defined in:
lib/htmlentities/decoder.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(flavor) ⇒ Decoder

Returns a new instance of Decoder.



3
4
5
6
7
# File 'lib/htmlentities/decoder.rb', line 3

def initialize(flavor)
  @flavor = flavor
  @map = HTMLEntities::MAPPINGS[@flavor]
  @named_entity_regexp = named_entity_regexp
end

Instance Method Details

#decode(source) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/htmlentities/decoder.rb', line 9

def decode(source)
  source.to_s.gsub(@named_entity_regexp) {
    (codepoint = @map[$1]) ? [codepoint].pack('U') : $&
  }.gsub(/&#(?:([0-9]{1,7})|x([0-9a-f]{1,6}));/i) {
    $1 ? [$1.to_i].pack('U') : [$2.to_i(16)].pack('U')
  }
end