Module: Cleaners::ReplaceHTMLMarkup

Defined in:
lib/data_cleansing/cleaners.rb

Overview

Unescape HTML Markup ( case-insensitive )

Constant Summary collapse

HTML_MARKUP =
Regexp.compile(/&(amp|quot|gt|lt|apos|nbsp);/in)

Class Method Summary collapse

Class Method Details

.call(string) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/data_cleansing/cleaners.rb', line 65

def self.call(string)
  return string unless string.is_a?(String)

  string.gsub!(HTML_MARKUP) do |match|
    case match.downcase
    when "&"
      "&"
    when """
      '"'
    when ">"
      ">"
    when "<"
      "<"
    when "&apos;"
      "'"
    when "&nbsp;"
      " "
    else
      "&#{match};"
    end
  end || string
end