module Sterile

def encode_entities(string)


q{“Economy Hits Bottom,” ran the headline}.encode_entities # => “Economy Hits Bottom,” ran the headline

If a valid HTML entity is not possible, it will create a numeric entity.
Turn Unicode characters into their HTML equivilents.
def encode_entities(string)
  transmogrify(string) do |mapping, codepoint|
    if (32..126).include?(codepoint)
      mapping[0]
    else
      "&" + (mapping[2] || "#" + codepoint.to_s) + ";"
    end
  end
end