Module: FriendlyUrl

Included in:
HasPermalink::InstanceMethods
Defined in:
lib/friendly_url.rb

Instance Method Summary collapse

Instance Method Details

#normalize(str) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/friendly_url.rb', line 4

def normalize(str)
  unless str.blank?
    n = str.mb_chars.downcase.to_s.strip
    n.gsub!(/[àáâãäåāă]/,     'a')
    n.gsub!(/æ/,              'ae')
    n.gsub!(/[ďđ]/,           'd')
    n.gsub!(/[çćčĉċ]/,        'c')
    n.gsub!(/[èéêëēęěĕė]/,    'e')
    n.gsub!(/ƒ/,              'f')
    n.gsub!(/[ĝğġģ]/,         'g')
    n.gsub!(/[ĥħ]/,           'h')
    n.gsub!(/[ììíîïīĩĭ]/,     'i')
    n.gsub!(/[įıijĵ]/,         'j')
    n.gsub!(/[ķĸ]/,           'k')
    n.gsub!(/[łľĺļŀ]/,        'l')
    n.gsub!(/[ñńňņʼnŋ]/,       'n')
    n.gsub!(/[òóôõöøōőŏŏ]/,   'o')
    n.gsub!(/œ/,              'oe')
    n.gsub!(/ą/,              'q')
    n.gsub!(/[ŕřŗ]/,          'r')
    n.gsub!(/[śšşŝș]/,        's')
    n.gsub!(/[ťţŧț]/,         't')
    n.gsub!(/[ùúûüūůűŭũų]/,   'u')
    n.gsub!(/ŵ/,              'w')
    n.gsub!(/[ýÿŷ]/,          'y')
    n.gsub!(/[žżź]/,          'z')
    n.gsub!(/\s+/,            '-')
    n.gsub!(/[^\sa-z0-9_-]/,  '')
    n.gsub!(/-{2,}/,          '-')
    n.gsub!(/^-/,             '')
    n.gsub!(/-$/,             '')
    n
  end
end