Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This works as I suppose you'd like it to have: translating characters in the array and leaving those not in there as they are:</p> <pre><code># encoding: utf-8 lookup = {'Š'=&gt;'S', 'š'=&gt;'s', 'Ð'=&gt;'Dj','Ž'=&gt;'Z', 'ž'=&gt;'z', 'À'=&gt;'A', 'Á'=&gt;'A', 'Â'=&gt;'A', 'Ã'=&gt;'A', 'Ä'=&gt;'A', 'Å'=&gt;'A', 'Æ'=&gt;'A', 'Ç'=&gt;'C', 'È'=&gt;'E', 'É'=&gt;'E', 'Ê'=&gt;'E', 'Ë'=&gt;'E', 'Ì'=&gt;'I', 'Í'=&gt;'I', 'Î'=&gt;'I', 'Ï'=&gt;'I', 'Ñ'=&gt;'N', 'Ò'=&gt;'O', 'Ó'=&gt;'O', 'Ô'=&gt;'O', 'Õ'=&gt;'O', 'Ö'=&gt;'O', 'Ø'=&gt;'O', 'Ù'=&gt;'U', 'Ú'=&gt;'U', 'Û'=&gt;'U', 'Ü'=&gt;'U', 'Ý'=&gt;'Y', 'Þ'=&gt;'B', 'ß'=&gt;'Ss','à'=&gt;'a', 'á'=&gt;'a', 'â'=&gt;'a', 'ã'=&gt;'a', 'ä'=&gt;'a', 'å'=&gt;'a', 'æ'=&gt;'a', 'ç'=&gt;'c', 'è'=&gt;'e', 'é'=&gt;'e', 'ê'=&gt;'e', 'ë'=&gt;'e', 'ì'=&gt;'i', 'í'=&gt;'i', 'î'=&gt;'i', 'ï'=&gt;'i', 'ð'=&gt;'o', 'ñ'=&gt;'n', 'ò'=&gt;'o', 'ó'=&gt;'o', 'ô'=&gt;'o', 'õ'=&gt;'o', 'ö'=&gt;'o', 'ø'=&gt;'o', 'ù'=&gt;'u', 'ú'=&gt;'u', 'û'=&gt;'u', 'ý'=&gt;'y', 'ý'=&gt;'y', 'þ'=&gt;'b', 'ÿ'=&gt;'y', 'ƒ'=&gt;'f'} clean_genre = entry["genre"].chars.to_a.map { |x| if lookup.has_key?(x) lookup[x] else x end }.join </code></pre> <p>for example this:</p> <pre><code>'aŠšŽž'.chars.to_a.map { |x| if lookup.has_key?(x) lookup[x] else x end }.join </code></pre> <p>gives you 'aSsZz'. </p> <p>Or move the block logic into the lookup table itself (thanks to steenslag for simplifying the default proc solution!):</p> <pre><code>lookup.default_proc = proc { |hash, key| key } </code></pre> <p>then the call would look as follows:</p> <pre><code>puts 'aŠšŽž'.chars.to_a.map { |x| lookup[x] }.join </code></pre> <p>Or even better (thanks again to steenslag for pointing out):</p> <pre><code>puts 'aŠšŽž'.gsub(/./) { |x| lookup[x] } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload