greek_string_utils 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- greek_string_utils (0.0.1)
4
+ greek_string_utils (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.rdoc CHANGED
@@ -28,4 +28,4 @@ And normally in application_helper.rb:
28
28
 
29
29
  == Credits
30
30
 
31
- Eric Coen https://github.com/eirc
31
+ Eric Cohen https://github.com/eirc
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'pry'
4
+
3
5
  module GreekStringUtils
4
6
  def upperfix(string)
5
7
  string.chars.map do |char|
@@ -56,4 +58,44 @@ module GreekStringUtils
56
58
  end
57
59
  end.join
58
60
  end
61
+
62
+ def remove_accents(string)
63
+ string.chars.map do |char|
64
+ case char
65
+ when 'ά' then 'α'
66
+ when 'έ' then 'ε'
67
+ when 'ή' then 'η'
68
+ when 'ί' then 'ι'
69
+ when 'ό' then 'ο'
70
+ when 'ύ' then 'υ'
71
+ when 'ώ' then 'ω'
72
+ when 'Ά' then 'Α'
73
+ when 'Έ' then 'Ε'
74
+ when 'Ή' then 'Η'
75
+ when 'Ί' then 'Ι'
76
+ when 'Ϊ' then 'Ι'
77
+ when 'Ό' then 'Ο'
78
+ when 'Ύ' then 'Υ'
79
+ when 'Ώ' then 'Ω'
80
+ when 'ϊ' then 'ι'
81
+ when 'ϋ' then 'υ'
82
+ when 'ΐ' then 'ι'
83
+ when 'ΰ' then 'υ'
84
+ else char
85
+ end
86
+ end.join
87
+ end
88
+
89
+ def has_accent?(string)
90
+ string.match(/ά|έ|ή|ί|ό|ύ|ώ|Ά|Έ|Ή|Ί|Ϊ|Ό|Ύ|Ώ|ϊ|ϋ|ΐ|ΰ/) ? true : false
91
+ end
92
+
93
+ def greek_sort(array)
94
+ array.sort do |a, b|
95
+ x = remove_accents(a)
96
+ y = remove_accents(b)
97
+
98
+ x == y ? a <=> b : x <=> y
99
+ end
100
+ end
59
101
  end
@@ -1,3 +1,3 @@
1
1
  module GreekStringUtils
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -16,4 +16,34 @@ describe 'GreekStringUtils' do
16
16
  upperfix(a).should eql('ΑΥΤΟ EINAI ΕΝΑ TEST')
17
17
  end
18
18
 
19
+ it 'should remove accents & diaeresis' do
20
+ a = 'αυτο είναι μϊα φράση με τόνους και δΪαρεΐσεις'
21
+ remove_accents(a).should eql('αυτο ειναι μια φραση με τονους και δΙαρεισεις')
22
+ end
23
+
24
+ it 'should make valid sorting to greek letters' do
25
+ a = %w(α ά)
26
+ greek_sort(a).should eql(%w(ά α))
27
+ end
28
+
29
+ it 'should detect accents in greek letters' do
30
+ a = 'τραγούδι'
31
+ has_accent?(a).should eql(true)
32
+ end
33
+
34
+ it 'should make valid sorting to greek word' do
35
+ a = %w(άβ αα)
36
+ greek_sort(a).should eql(%w(αα άβ))
37
+ end
38
+
39
+ it 'should sort valid taking account accents' do
40
+ a = %w(αβ άβ άα αα)
41
+ greek_sort(a).should eql(%w(άα αα άβ αβ))
42
+ end
43
+
44
+ it 'should sort mixed letters' do
45
+ a = %w(α αβ άβας)
46
+ greek_sort(a).should eql(%w(α αβ άβας))
47
+ end
48
+
19
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greek_string_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-05 00:00:00.000000000 Z
12
+ date: 2012-02-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Simple library to correct upcase in greek
15
15
  email:
@@ -44,7 +44,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
44
44
  version: '0'
45
45
  segments:
46
46
  - 0
47
- hash: 480759795
47
+ hash: 799179521
48
48
  required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  segments:
55
55
  - 0
56
- hash: 480759795
56
+ hash: 799179521
57
57
  requirements: []
58
58
  rubyforge_project:
59
59
  rubygems_version: 1.8.14