Class: HTMLEntities::Encoder

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

Overview

:nodoc:

Constant Summary

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

Instance Method Summary (collapse)

Constructor Details

- (Encoder) initialize(flavor, instructions)

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

- (Object) encode(source)



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

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

- (Object) prepare(string)

:nodoc:



24
25
26
# File 'lib/htmlentities/encoder.rb', line 24

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