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]
  @entity_regexp = entity_regexp
end

Instance Method Details

#decode(source) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/htmlentities/decoder.rb', line 9

def decode(source)
  prepare(source).gsub(@entity_regexp){
    if $1 && codepoint = @map[$1]
      [codepoint].pack('U')
    elsif $2
      [$2.to_i(10)].pack('U')
    elsif $3
      [$3.to_i(16)].pack('U')
    else
      $&
    end
  }
end