Class: HTMLEntities::Decoder

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

Overview

:nodoc:

Instance Method Summary (collapse)

Constructor Details

- (Decoder) initialize(flavor)

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

- (Object) decode(source)



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

- (Object) prepare(string)

:nodoc:



25
26
27
# File 'lib/htmlentities/decoder.rb', line 25

def prepare(string) #:nodoc:
  string.to_s
end