Module: GreekStringUtils

Defined in:
lib/greek_string_utils.rb,
lib/greek_string_utils/version.rb

Constant Summary collapse

VERSION =
"0.0.5"

Instance Method Summary collapse

Instance Method Details

#greek_sort(array) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/greek_string_utils.rb', line 92

def greek_sort(array)
  array.sort do |a, b|
    x = remove_accents(a)
    y = remove_accents(b)

    x == y ?  a <=> b : x <=> y
  end
end

#has_accent?(string) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/greek_string_utils.rb', line 88

def has_accent?(string)
  string.to_s.match(/ά|έ|ή|ί|ό|ύ|ώ|Ά|Έ|Ή|Ί|Ϊ|Ό|Ύ|Ώ|ϊ|ϋ|ΐ|ΰ/) ? true : false
end

#remove_accents(string) ⇒ Object



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
# File 'lib/greek_string_utils.rb', line 61

def remove_accents(string)
 string.to_s.chars.map do |char|
    case char
    when 'ά' then 'α'
    when 'έ' then 'ε'
    when 'ή' then 'η'
    when 'ί' then 'ι'
    when 'ό' then 'ο'
    when 'ύ' then 'υ'
    when 'ώ' then 'ω'
    when 'Ά' then 'Α'
    when 'Έ' then 'Ε'
    when 'Ή' then 'Η'
    when 'Ί' then 'Ι'
    when 'Ϊ' then 'Ι'
    when 'Ό' then 'Ο'
    when 'Ύ' then 'Υ'
    when 'Ώ' then 'Ω'
    when 'ϊ' then 'ι'
    when 'ϋ' then 'υ'
    when 'ΐ' then 'ι'
    when 'ΰ' then 'υ'
    else char
    end
  end.join
end

#upperfix(string) ⇒ 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/greek_string_utils.rb', line 4

def upperfix(string)
  string.to_s.chars.map do |char|
    case char
    # Downcase characters
    when 'α' then 'Α'
    when 'β' then 'Β'
    when 'γ' then 'Γ'
    when 'δ' then 'Δ'
    when 'ε' then 'Ε'
    when 'ζ' then 'Ζ'
    when 'η' then 'Η'
    when 'θ' then 'Θ'
    when 'ι' then 'Ι'
    when 'κ' then 'Κ'
    when 'λ' then 'Λ'
    when 'μ' then 'Μ'
    when 'ν' then 'Ν'
    when 'ξ' then 'Ξ'
    when 'ο' then 'Ο'
    when 'π' then 'Π'
    when 'ρ' then 'Ρ'
    when 'σ' then 'Σ'
    when 'ς' then 'Σ'
    when 'τ' then 'Τ'
    when 'υ' then 'Υ'
    when 'φ' then 'Φ'
    when 'χ' then 'Χ'
    when 'ψ' then 'Ψ'
    when 'ω' then 'Ω'
    # Downcase characters with acute accents
    when 'ά' then 'Α'
    when 'έ' then 'Ε'
    when 'ή'
      string.to_s.size > 1 ? 'H' : 'Ή'
    when 'ί' then 'Ι'
    when 'ό' then 'Ο'
    when 'ύ' then 'Υ'
    when 'ώ' then 'Ω'
    # Upcase characters with acute accents
    when 'Ά' then 'Α'
    when 'Έ' then 'Ε'
    when 'Ή' then 'Η'
    when 'Ί' then 'Ι'
    when 'Ό' then 'Ο'
    when 'Ύ' then 'Υ'
    when 'Ώ' then 'Ω'
    # Downcase characters with acute and diaeresis accents (diaeresis preserved in upcase)
    when 'ϊ' then 'Ϊ'
    when 'ϋ' then 'Ϋ'
    # Downcase characters with acute and diaeresis accents (diaeresis preserved in upcase)
    when 'ΐ' then 'Ϊ'
    when 'ΰ' then 'Ϋ'
    else char.upcase
    end
  end.join
end