Module: Linkage::Decollation

Included in:
Group
Defined in:
lib/linkage/decollation.rb

Instance Method Summary collapse

Instance Method Details

#decollate(string, database_type, collation) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/linkage/decollation.rb', line 4

def decollate(string, database_type, collation)
  case database_type
  when :mysql
    decollate_mysql(string, collation)
  else
    string
  end
end

#decollate_mysql(string, collation) ⇒ Object



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

def decollate_mysql(string, collation)
  case collation
  when "latin1_swedish_ci"
    decollate_mysql_latin1_swedish_ci(string)
  else
    string
  end
end

#decollate_mysql_latin1_swedish_ci(string) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/linkage/decollation.rb', line 22

def decollate_mysql_latin1_swedish_ci(string)
  result = string.strip
  result.each_char.with_index do |char, i|
    case char
    when 'A', 'a', 'À', 'Á', 'Â', 'Ã', 'à', 'á', 'â', 'ã'
      result[i] = 'A'
    when 'B', 'b'
      result[i] = 'B'
    when 'C', 'c', 'Ç', 'ç'
      result[i] = 'C'
    when 'D', 'd', 'Ð', 'ð'
      result[i] = 'D'
    when 'E', 'e', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë'
      result[i] = 'E'
    when 'F', 'f'
      result[i] = 'F'
    when 'G', 'g'
      result[i] = 'G'
    when 'H', 'h'
      result[i] = 'H'
    when 'I', 'i', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï'
      result[i] = 'I'
    when 'J', 'j'
      result[i] = 'J'
    when 'K', 'k'
      result[i] = 'K'
    when 'L', 'l'
      result[i] = 'L'
    when 'M', 'm'
      result[i] = 'M'
    when 'N', 'n', 'Ñ', 'ñ'
      result[i] = 'N'
    when 'O', 'o', 'Ò', 'Ó', 'Ô', 'Õ', 'ò', 'ó', 'ô', 'õ'
      result[i] = 'O'
    when 'P', 'p'
      result[i] = 'P'
    when 'Q', 'q'
      result[i] = 'Q'
    when 'R', 'r'
      result[i] = 'R'
    when 'S', 's'
      result[i] = 'S'
    when 'T', 't'
      result[i] = 'T'
    when 'U', 'u', 'Ù', 'Ú', 'Û', 'ù', 'ú', 'û'
      result[i] = 'U'
    when 'V', 'v'
      result[i] = 'V'
    when 'W', 'w'
      result[i] = 'W'
    when 'X', 'x'
      result[i] = 'X'
    when 'Y', 'y', 'Ü', 'Ý', 'ü', 'ý'
      result[i] = 'Y'
    when 'Z', 'z'
      result[i] = 'Z'
    when '[', 'Å', 'å'
      result[i] = '['
    when '\\', 'Ä', 'Æ', 'ä', 'æ'
      result[i] = '\\'
    when ']', 'Ö', 'ö'
      result[i] = ']'
    when 'Ø', 'ø'
      result[i] = 'Ø'
    when 'Þ', 'þ'
      result[i] = 'Þ'
    end
  end
  result
end