Method: Stringex::Unidecoder.decode

Defined in:
lib/stringex/unidecoder.rb

.decode(string) ⇒ Object

Returns string with its UTF-8 characters transliterated to ASCII ones

You’re probably better off just using the added String#to_ascii



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/stringex/unidecoder.rb', line 16

def decode(string)
  string.gsub(/[^\x00-\x00]/u) do |codepoint|
    if localized = translate(codepoint)
      localized
    else
      begin
        unpacked = codepoint.unpack("U")[0]
        CODEPOINTS[code_group(unpacked)][grouped_point(unpacked)]
      rescue
        # Hopefully this won't come up much
        # TODO: Make this note something to the user that is reportable to me perhaps
        "?"
      end
    end
  end
end