Class: Picky::CharacterSubstituters::WestEuropean

Inherits:
Base
  • Object
show all
Defined in:
lib/picky/character_substituters/west_european.rb

Overview

Substitutes Umlauts like ä, ö, ü => ae, oe, ue. (and more, see specs)

Instance Method Summary collapse

Methods inherited from Base

#initialize, #to_s

Constructor Details

This class inherits a constructor from Picky::CharacterSubstituters::Base

Instance Method Details

#substitute(text) ⇒ Object

Substitutes occurrences of certain characters (like Umlauts) with ASCII representations of them.

Examples:

ä -> ae
Ö -> Oe
ß -> ss
ç -> c

(See the associated spec for all examples)



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/picky/character_substituters/west_european.rb', line 26

def substitute text
  trans = @chars.new(text).normalize :kd

  # Substitute special cases.
  #
  trans.gsub! 'ß', 'ss'

  # Substitute umlauts (of A,O,U,a,o,u).
  #
  trans.gsub! /([AOUaou])\314\210/u, '\1e'

  # Get rid of ecutes, graves etc.
  #
  trans.unpack('U*').select { |cp|
    cp < 0x0300 || cp > 0x035F
  }.pack 'U*'
end