Module: StrSanitizer::HtmlEntities

Included in:
StrSanitizer
Defined in:
lib/str_sanitizer/html_entities.rb

Overview

This modules encodes and decodes HTML Entities of a string

Author: Jakaria (mailto: [email protected]) Copyright: Copyright © 2017 Jakaria

Instance Method Summary collapse

Instance Method Details

#html_decode(string) ⇒ Object

Decodes the HTML entities of the given string

Params:

str

A string which needs to be decoded to html entities

Returns:

string

A string with decoded HTML entities string



41
42
43
44
# File 'lib/str_sanitizer/html_entities.rb', line 41

def html_decode(string)
  @coder = HTMLEntities.new
  @coder.decode(string)
end

#html_encode(string, *options) ⇒ Object

Encodes the HTML entities of the given string

Params:

str

A string which needs to be escaped from html entities

options

Options for encoding. You can provide one or more than one option. If no option is given, :basic option will be used by default. Options available :basic, :named, :decimal, :hexadecimal

Returns:

string

An HTML entities escaped string



29
30
31
32
# File 'lib/str_sanitizer/html_entities.rb', line 29

def html_encode(string, *options)
  @coder = HTMLEntities.new
  @coder.encode(string, *options)
end

#initizalizeObject

Instantiate htmlentities class to use it for encoding and decoding html entities

Params: none



15
16
17
# File 'lib/str_sanitizer/html_entities.rb', line 15

def initizalize
  @coder = HTMLEntities.new
end