module HtmlentityTranslator::EntityMaper

Constants

HTML_ENTITIES

Public Class Methods

decode_entities(str) click to toggle source
# File lib/htmlentity_translator/entity_maper.rb, line 346
def self.decode_entities(str)
  str.gsub /&.*?;/ do |match|
    arr = HTML_ENTITIES.select { |arr| arr[1]==match || arr[2]==match }.first
    if arr
      arr[0]
    else
      match
    end
  end
end
encode_entities(str) click to toggle source
# File lib/htmlentity_translator/entity_maper.rb, line 335
def self.encode_entities(str)
  str.gsub /([^[:ascii:]]|&)/ do|match|
    arr = HTML_ENTITIES.select { |arr| arr[0]==match }.first
    if arr
      arr[1].empty? ? arr[2] : arr[1]
    else
      match
    end
  end
end