Module: HtmlentityTranslator::EntityMaper

Defined in:
lib/htmlentity_translator/entity_maper.rb

Constant Summary collapse

HTML_ENTITIES =
[[' ', ' ', ' '],
['!', '', '!'],
['"', '', '"'],
['#', '', '#'],
['$', '', '$'],
['%', '', '%'],
['&', '&', '&'],
["'", '', '''],
['(', '', '('],
[')', '', ')'],
['*', '', '*'],
['+', '', '+'],
[',', '', ','],
['-', '', '-'],
['.', '', '.'],
['/', '', '/'],
['0', '', '0'],
['1', '', '1'],
['2', '', '2'],
['3', '', '3'],
['4', '', '4'],
['5', '', '5'],
['6', '', '6'],
['7', '', '7'],
['8', '', '8'],
['9', '', '9'],
[':', '', ':'],
[';', '', '&#59;'],
['<', '&lt;', '&#60;'],
['=', '', '&#61;'],
['>', '&gt;', '&#62;'],
['?', '', '&#63;'],
['@', '', '&#64;'],
['A', '', '&#65;'],
['B', '', '&#66;'],
['C', '', '&#67;'],
['D', '', '&#68;'],
['E', '', '&#69;'],
['F', '', '&#70;'],
['G', '', '&#71;'],
['H', '', '&#72;'],
['I', '', '&#73;'],
['J', '', '&#74;'],
['K', '', '&#75;'],
['L', '', '&#76;'],
['M', '', '&#77;'],
['N', '', '&#78;'],
['O', '', '&#79;'],
['P', '', '&#80;'],
['Q', '', '&#81;'],
['R', '', '&#82;'],
['S', '', '&#83;'],
['T', '', '&#84;'],
['U', '', '&#85;'],
['V', '', '&#86;'],
['W', '', '&#87;'],
['X', '', '&#88;'],
['Y', '', '&#89;'],
['Z', '', '&#90;'],
['[', '', '&#91;'],
["\\", '', '&#92;'],
[']', '', '&#93;'],
['^', '', '&#94;'],
['_', '', '&#95;'],
['`', '', '&#96;'],
['a', '', '&#97;'],
['b', '', '&#98;'],
['c', '', '&#99;'],
['d', '', '&#100;'],
['e', '', '&#101;'],
['f', '', '&#102;'],
['g', '', '&#103;'],
['h', '', '&#104;'],
['i', '', '&#105;'],
['j', '', '&#106;'],
['k', '', '&#107;'],
['l', '', '&#108;'],
['m', '', '&#109;'],
['n', '', '&#110;'],
['o', '', '&#111;'],
['p', '', '&#112;'],
['q', '', '&#113;'],
['r', '', '&#114;'],
['s', '', '&#115;'],
['t', '', '&#116;'],
['u', '', '&#117;'],
['v', '', '&#118;'],
['w', '', '&#119;'],
['x', '', '&#120;'],
['y', '', '&#121;'],
['z', '', '&#122;'],
['{', '', '&#123;'],
['|', '', '&#124;'],
['}', '', '&#125;'],
['~', '', '&#126;'],
['À', '&Agrave;', '&#192;'],
['Á', '&Aacute;', '&#193;'],
['Â', '&Acirc;', '&#194;'],
['Ã', '&Atilde;', '&#195;'],
['Ä', '&Auml;', '&#196;'],
['Å', '&Aring;', '&#197;'],
['Æ', '&AElig;', '&#198;'],
['Ç', '&Ccedil;', '&#199;'],
['È', '&Egrave;', '&#200;'],
['É', '&Eacute;', '&#201;'],
#		&Ecirc;		&#202;
['Ë', '&Euml;', '&#203;'],
['Ì', '&Igrave;', '&#204;'],
['Í', '&Iacute;', '&#205;'],
['Î', '&Icirc;', '&#206;'],
['Ï', '&Iuml;', '&#207;'],
['Ð', '&ETH;', '&#208;'],
['Ñ', '&Ntilde;', '&#209;'],
['Ò', '&Ograve;', '&#210;'],
['Ó', '&Oacute;', '&#211;'],
['Ô', '&Ocirc;', '&#212;'],
['Õ', '&Otilde;', '&#213;'],
['Ö', '&Ouml;', '&#214;'],
['Ø', '&Oslash;', '&#216;'],
['Ù', '&Ugrave;', '&#217;'],
['Ú', '&Uacute;', '&#218;'],
['Û', '&Ucirc;', '&#219;'],
['Ü', '&Uuml;', '&#220;'],
['Ý', '&Yacute;', '&#221;'],
['Þ', '&THORN;', '&#222;'],
['ß', '&szlig;', '&#223;'],
['à', '&agrave;', '&#224;'],
['á', '&aacute;', '&#225;'],
['â', '&acirc;', '&#226;'],
['ã', '&atilde;', '&#227;'],
['ä', '&auml;', '&#228;'],
['å', '&aring;', '&#229;'],
['æ', '&aelig;', '&#230;'],
['ç', '&ccedil;', '&#231;'],
['è', '&egrave;', '&#232;'],
['é', '&eacute;', '&#233;'],
['ê', '&ecirc;', '&#234;'],
['ë', '&euml;', '&#235;'],
['ì', '&igrave;', '&#236;'],
['í', '&iacute;', '&#237;'],
['î', '&icirc;', '&#238;'],
['ï', '&iuml;', '&#239;'],
['ð', '&eth;', '&#240;'],
['ñ', '&ntilde;', '&#241;'],
['ò', '&ograve;', '&#242;'],
['ó', '&oacute;', '&#243;'],
['ô', '&ocirc;', '&#244;'],
['õ', '&otilde;', '&#245;'],
['ö', '&ouml;', '&#246;'],
['ø', '&oslash;', '&#248;'],
['ù', '&ugrave;', '&#249;'],
['ú', '&uacute;', '&#250;'],
['û', '&ucirc;', '&#251;'],
['ü', '&uuml;', '&#252;'],
['ý', '&yacute;', '&#253;'],
['þ', '&thorn;', '&#254;'],
['ÿ', '&yuml;', '&#255;'],
[' ', '&nbsp;', '&#160;'],
['¡', '&iexcl;', '&#161;'],
['¢', '&cent;', '&#162;'],
['£', '&pound;', '&#163;'],
['¤', '&curren;', '&#164;'],
['¥', '&yen;', '&#165;'],
['¦', '&brvbar;', '&#166;'],
['§', '&sect;', '&#167;'],
['¨', '&uml;', '&#168;'],
['©', '&copy;', '&#169;'],
['ª', '&ordf;', '&#170;'],
['«', '&laquo;', '&#171;'],
['¬', '&not;', '&#172;'],
#		&shy;		&#173;
['®', '&reg;', '&#174;'],
['¯', '&macr;', '&#175;'],
['°', '&deg;', '&#176;'],
['±', '&plusmn;', '&#177;'],
['²', '&sup2;', '&#178;'],
['³', '&sup3;', '&#179;'],
['´', '&acute;', '&#180;'],
['µ', '&micro;', '&#181;'],
['', '&para;', '&#182;'],
['¸', '&cedil;', '&#184;'],
['¹', '&sup1;', '&#185;'],
['º', '&ordm;', '&#186;'],
['»', '&raquo;', '&#187;'],
['¼', '&frac14;', '&#188;'],
['½', '&frac12;', '&#189;'],
['¾', '&frac34;', '&#190;'],
['¿', '&iquest;', '&#191;'],
['×', '&times;', '&#215;'],
['÷', '&divide;', '&#247;'],
['', '&forall;', '&#8704;'],
['', '&part;', '&#8706;'],
['', '&exist;', '&#8707;'],
['', '&empty;', '&#8709;'],
['', '&nabla;', '&#8711;'],
['', '&isin;', '&#8712;'],
['', '&notin;', '&#8713;'],
['', '&ni;', '&#8715;'],
['', '&prod;', '&#8719;'],
['', '&sum;', '&#8721;'],
['', '&minus;', '&#8722;'],
['', '&lowast;', '&#8727;'],
['', '&radic;', '&#8730;'],
['', '&prop;', '&#8733;'],
['', '&infin;', '&#8734;'],
['', '&ang;', '&#8736;'],
['', '&and;', '&#8743;'],
['', '&or;', '&#8744;'],
['', '&cap;', '&#8745;'],
['', '&cup;', '&#8746;'],
['', '&int;', '&#8747;'],
['', '&there4;', '&#8756;'],
['', '&sim;', '&#8764;'],
['', '&cong;', '&#8773;'],
['', '&asymp;', '&#8776;'],
['', '&ne;', '&#8800;'],
['', '&equiv;', '&#8801;'],
['', '&le;', '&#8804;'],
['', '&ge;', '&#8805;'],
['', '&sub;', '&#8834;'],
['', '&sup;', '&#8835;'],
['', '&nsub;', '&#8836;'],
['', '&sube;', '&#8838;'],
['', '&supe;', '&#8839;'],
['', '&oplus;', '&#8853;'],
['', '&otimes;', '&#8855;'],
['', '&perp;', '&#8869;'],
['', '&sdot;', '&#8901;'],
['Α', '&Alpha;', '&#913;'],
['Β', '&Beta;', '&#914;'],
['Γ', '&Gamma;', '&#915;'],
['Δ', '&Delta;', '&#916;'],
['Ε', '&Epsilon;', '&#917;'],
['Ζ', '&Zeta;', '&#918;'],
['Η', '&Eta;', '&#919;'],
['Θ', '&Theta;', '&#920;'],
['Ι', '&Iota;', '&#921;'],
['Κ', '&Kappa;', '&#922;'],
['Λ', '&Lambda;', '&#923;'],
['Μ', '&Mu;', '&#924;'],
['Ν', '&Nu;', '&#925;'],
['Ξ', '&Xi;', '&#926;'],
['Ο', '&Omicron;', '&#927;'],
['Π', '&Pi;', '&#928;'],
['Ρ', '&Rho;', '&#929;'],
['Σ', '&Sigma;', '&#931;'],
['Τ', '&Tau;', '&#932;'],
['Υ', '&Upsilon;', '&#933;'],
['Φ', '&Phi;', '&#934;'],
['Χ', '&Chi;', '&#935;'],
['Ψ', '&Psi;', '&#936;'],
['Ω', '&Omega;', '&#937;'],
['α', '&alpha;', '&#945;'],
['β', '&beta;', '&#946;'],
['γ', '&gamma;', '&#947;'],
['δ', '&delta;', '&#948;'],
['ε', '&epsilon;', '&#949;'],
['ζ', '&zeta;', '&#950;'],
['η', '&eta;', '&#951;'],
['θ', '&theta;', '&#952;'],
['ι', '&iota;', '&#953;'],
['κ', '&kappa;', '&#954;'],
['λ', '&lambda;', '&#955;'],
['μ', '&mu;', '&#956;'],
['ν', '&nu;', '&#957;'],
['ξ', '&xi;', '&#958;'],
['ο', '&omicron;', '&#959;'],
['π', '&pi;', '&#960;'],
['ρ', '&rho;', '&#961;'],
['ς', '&sigmaf;', '&#962;'],
['σ', '&sigma;', '&#963;'],
['σ', '&sigma;', '&#963;'],
['τ', '&tau;', '&#964;'],
['υ', '&upsilon;', '&#965;'],
['φ', '&phi;', '&#966;'],
['χ', '&chi;', '&#967;'],
['ψ', '&psi;', '&#968;'],
['ω', '&omega;', '&#969;'],
['ϑ', '&thetasym;', '&#977;'],
['ϒ', '&upsih;', '&#978;'],
['ϖ', '&piv;', '&#982;'],
['Œ', '&OElig;', '&#338;'],
['œ', '&oelig;', '&#339;'],
['Š', '&Scaron;', '&#352;'],
['š', '&scaron;', '&#353;'],
['Ÿ', '&Yuml;', '&#376;'],
['ƒ', '&fnof;', '&#402;'],
['ˆ', '&circ;', '&#710;'],
['˜', '&tilde;', '&#732;'],
['', '&ensp;', '&#8194;'],
['', '&emsp;', '&#8195;'],
['', '&thinsp;', '&#8201;'],
['', '&zwnj;', '&#8204;'],
['', '&zwj;', '&#8205;'],
['', '&lrm;', '&#8206;'],
['', '&rlm;', '&#8207;'],
['', '&ndash;', '&#8211;'],
['', '&mdash;', '&#8212;'],
['', '&lsquo;', '&#8216;'],
['', '&rsquo;', '&#8217;'],
['', '&sbquo;', '&#8218;'],
['', '&ldquo;', '&#8220;'],
['', '&rdquo;', '&#8221;'],
['', '&bdquo;', '&#8222;'],
['', '&dagger;', '&#8224;'],
['', '&Dagger;', '&#8225;'],
['', '&bull;', '&#8226;'],
['', '&hellip;', '&#8230;'],
['', '&permil;', '&#8240;'],
['', '&prime;', '&#8242;'],
['', '&Prime;', '&#8243;'],
['', '&lsaquo;', '&#8249;'],
['', '&rsaquo;', '&#8249;'],
['', '&oline;', '&#8254;'],
['', '&euro;', '&#8364;'],
['', '&trade;', '&#8482;'],
['', '&larr;', '&#8592;'],
['', '&uarr;', '&#8593;'],
['', '&rarr;', '&#8594;'],
['', '&darr;', '&#8595;'],
['', '&harr;', '&#8596;'],
['', '&crarr;', '&#8629;'],
['', '&lceil;', '&#8968;'],
['', '&rceil;', '&#8969;'],
['', '&lfloor;', '&#8970;'],
['', '&rfloor;', '&#8971;'],
['', '&loz;', '&#9674;'],
['', '&spades;', '&#9824;'],
['', '&clubs;', '&#9827;'],
['', '&hearts;', '&#9829;'],
['', '&diams;', '&#9830;']]

Class Method Summary collapse

Class Method Details

.decode_entities(str) ⇒ Object



346
347
348
349
350
351
352
353
354
355
# 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) ⇒ Object



335
336
337
338
339
340
341
342
343
344
# 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