Class: HTMLEntities::Encoder

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

Overview

:nodoc:

Constant Summary collapse

INSTRUCTIONS =
[:basic, :named, :decimal, :hexadecimal]

Instance Method Summary collapse

Constructor Details

#initialize(flavor, instructions) ⇒ Encoder

Returns a new instance of Encoder.



7
8
9
10
11
12
13
# File 'lib/htmlentities/encoder.rb', line 7

def initialize(flavor, instructions)
  @flavor = flavor
  instructions = [:basic] if instructions.empty?
  validate_instructions(instructions)
  build_basic_entity_encoder(instructions)
  build_extended_entity_encoder(instructions)
end

Instance Method Details

#encode(source) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/htmlentities/encoder.rb', line 15

def encode(source)
  post_process(
    prepare(source).
      gsub(basic_entity_regexp){ |match| encode_basic(match) }.
      gsub(extended_entity_regexp){ |match| encode_extended(match) }
  )
end