Module: SpeakingId

Defined in:
lib/speaking_id/speaking_id.rb,
lib/speaking_id/ascii_approximations.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Constant Summary collapse

ASCII_APPROXIMATIONS =
{
  196 => [65,  101], # Ä => Ae
  214 => [79,  101], # Ö => Oe
  220 => [85,  101], # Ü => Ue
  223 => [115, 115], # ß => ss
  228 => [97,  101], # ä => ae
  246 => [111, 101], # ö => oe
  252 => [117, 101]  # ü => ue
}.freeze

Class Method Summary collapse

Class Method Details

.approximate_char(char) ⇒ Object



22
23
24
25
26
27
# File 'lib/speaking_id/ascii_approximations.rb', line 22

def approximate_char(char)
  if ASCII_APPROXIMATIONS.include? char
    return ASCII_APPROXIMATIONS[char]
  end
  char
end

.included(base) ⇒ Object



2
3
4
# File 'lib/speaking_id/speaking_id.rb', line 2

def self.included(base)
  base.send :extend, ClassMethods
end

.replace_known_special_chars(chars) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/speaking_id/ascii_approximations.rb', line 13

def replace_known_special_chars(chars)
  chars = ActiveSupport::Multibyte.proxy_class.new(chars)
  chars = chars.normalize(:kc).unpack('U*')

  chars = chars.inject([]) do |result, char|
    result << approximate_char(char)
  end.flatten.pack('U*')
end