class ErbEscape::Decoder

Responsible for unescaping erb templates.

Constants

END_TAGS_REGEXP
REGEXP
START_TAGS_REGEXP

Public Class Methods

new(str) click to toggle source
# File lib/erb_escape/decoder.rb, line 12
def initialize(str)
  @str = str
end

Public Instance Methods

decode() click to toggle source
# File lib/erb_escape/decoder.rb, line 16
def decode
  @str.gsub(REGEXP) do
    match = Regexp.last_match
    decode_tag(code: match[2], indicator: match[1])
  end
end

Private Instance Methods

decode_tag(code:, indicator:) click to toggle source
# File lib/erb_escape/decoder.rb, line 25
def decode_tag(code:, indicator:)
  start_tag = START_TAGS.invert[indicator.to_s]
  unescaped_code = CGI.unescapeHTML(code)
  "<%#{start_tag}#{unescaped_code}%>"
end