turkish_support 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2d1af86e3516703c1a1a9c9b63a2f5084420c0b
4
- data.tar.gz: 29c3d95b0d17ed33157a1c3e6a82f24f03660fd2
3
+ metadata.gz: 3bf732fd5ed6e7e26aa61e8cc73a52ec9dcba34b
4
+ data.tar.gz: a6f21e3ac420c51565ce28c2529f61ad4cf753dc
5
5
  SHA512:
6
- metadata.gz: bee27f7790ae647404b90d9c291e6b062d51799bd0f61ac6d2c7950547bf146e02a1dc04f586c0be093c5c61962ba7524375105c54a13d54471602ccad17b800
7
- data.tar.gz: cd9a89e523e5def88c076dc5e686058b5c0bbd7101b9e01371283eb7c03d05853331a4b13bec50be7c12d0132c4f7eec8c4e1a3a9bd5a10c7dbb99a09c3e5160
6
+ metadata.gz: f3f0afc9b75f2d2f774e22a799e52b2495ba6e6d4884fd15cc7063d7921ae8c85b7eb0378894d45b494b34fe780841bf076b582ced5a12c79a4aa26e22eb403f
7
+ data.tar.gz: a8885b4cff7ebdc11d7f51e745d1d257a750d7c2de0848b006e479826eb3a5647a543293dc1081ae74241281341a9213aea86692fedaa709614e88f8fa1f898a
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # TurkishSupport
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/turkish_support.svg)](http://badge.fury.io/rb/turkish_support)
4
+ [![Build Status](https://travis-ci.org/sbagdat/turkish_support.svg?branch=master)](https://travis-ci.org/sbagdat/turkish_support)
4
5
 
5
6
  Turkish character support for some standard Ruby methods. This gem provide support for these methods:
6
7
  * `String#upcase`
@@ -12,9 +13,12 @@ Turkish character support for some standard Ruby methods. This gem provide suppo
12
13
  * `String#swapcase`
13
14
  * `String#swapcase!`
14
15
  * `String#casecmp`
16
+ * `Array#sort`
17
+ * `Array#sort!`
15
18
 
16
19
  Also gives you some new methods like:
17
20
  * `String#titleize`
21
+ * `String#titleize!`
18
22
 
19
23
  ## Requirements
20
24
 
@@ -70,6 +74,8 @@ Within the file which you added `using TurkishSupport` line to the top of the sc
70
74
  str #=> "ismail"
71
75
 
72
76
  "merhaba".capitalize #=> "Merhaba"
77
+
78
+ ["iki", "üç", "dört", "ılık", "iğne", "iyne"].sort #=> ["dört", "ılık", "iğne", "iki", "iyne", "üç"]
73
79
  ```
74
80
 
75
81
  __Note:__ If you also want to use original set of the core methods in the same scope, you can use `send` method like this:
@@ -1,13 +1,16 @@
1
- require "turkish_support/version"
2
1
  require "turkish_support/constants"
3
- require "turkish_support/helpers"
4
- require "turkish_support/upcase"
5
- require "turkish_support/downcase"
6
- require "turkish_support/capitalize"
7
- require "turkish_support/titleize"
8
- require "turkish_support/casecmp"
9
- require "turkish_support/swapcase"
2
+ require "turkish_support/version"
3
+
4
+ require "turkish_support/string/helpers"
5
+ require "turkish_support/string/upcase"
6
+ require "turkish_support/string/downcase"
7
+ require "turkish_support/string/capitalize"
8
+ require "turkish_support/string/titleize"
9
+ require "turkish_support/string/casecmp"
10
+ require "turkish_support/string/swapcase"
11
+
12
+ require "turkish_support/array/helpers"
13
+ require "turkish_support/array/sort"
10
14
 
11
15
  module TurkishSupport
12
16
  end
13
-
@@ -0,0 +1,17 @@
1
+ module TurkishSupport
2
+ refine Array do
3
+ def to_number_array(string)
4
+ string.split('').map{|c| integer_order(c) }
5
+ end
6
+
7
+ def integer_order(char)
8
+ if char.match(/[ı]/)
9
+ NORMALIZED_CHARS[char].ord - 0.5
10
+ elsif char.match(/[çÇğĞİöÖşŞüÜ]/)
11
+ NORMALIZED_CHARS[char].ord + 0.5
12
+ else
13
+ char.ord
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module TurkishSupport
2
+ refine Array do
3
+ def sort
4
+ self.sort_by do |item|
5
+ to_number_array(item)
6
+ end
7
+ end
8
+
9
+ def sort!
10
+ replace(sort)
11
+ end
12
+ end
13
+ end
@@ -1,4 +1,21 @@
1
+ module TurkishSupport
1
2
  UNSUPPORTED_CHARS = {
2
3
  downcase: 'çğıiöşü',
3
4
  upcase: 'ÇĞIİÖŞÜ'
4
5
  }
6
+
7
+ NORMALIZED_CHARS = {
8
+ 'ç' => 'c',
9
+ 'Ç' => 'C',
10
+ 'ğ' => 'g',
11
+ 'Ğ' => 'G',
12
+ 'ı' => 'i',
13
+ 'İ' => 'I',
14
+ 'ö' => 'o',
15
+ 'Ö' => 'O',
16
+ 'ş' => 's',
17
+ 'Ş' => 'S',
18
+ 'ü' => 'u',
19
+ 'Ü' => 'U'
20
+ }
21
+ end
@@ -1,7 +1,7 @@
1
1
  module TurkishSupport
2
2
  refine String do
3
3
  def capitalize
4
- [self[0].change_chars_for_upcase.send(:upcase), self[1..-1]].join
4
+ [chr.change_chars_for_upcase.send(:upcase), self[1..-1]].join
5
5
  end
6
6
 
7
7
  def capitalize!
@@ -9,11 +9,11 @@ module TurkishSupport
9
9
  end
10
10
 
11
11
  def is_unsupported_downcase?
12
- UNSUPPORTED_CHARS[:downcase].include? self
12
+ UNSUPPORTED_CHARS[:downcase].include? chr
13
13
  end
14
14
 
15
15
  def is_unsupported_upcase?
16
- UNSUPPORTED_CHARS[:upcase].include? self
16
+ UNSUPPORTED_CHARS[:upcase].include? chr
17
17
  end
18
18
 
19
19
  def is_unsupported?
@@ -0,0 +1,11 @@
1
+ module TurkishSupport
2
+ refine String do
3
+ def titleize
4
+ split.map{ |w| w.downcase.capitalize }.join(' ')
5
+ end
6
+
7
+ def titleize!
8
+ replace(titleize)
9
+ end
10
+ end
11
+ end
File without changes
@@ -1,3 +1,3 @@
1
1
  module TurkishSupport
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -101,15 +101,30 @@ module TurkishSupport
101
101
  end
102
102
 
103
103
  describe "#titleize" do
104
- it "upcases first character of all words" do
105
- titleized = "merhaba çamur ismet".titleize
106
- expect(titleized).to eq("Merhaba Çamur İsmet")
107
- end
104
+ context "with non-destructive version" do
105
+ it "does not change the original value of the string" do
106
+ word = "mERHABA çAMUR iSMETOĞULLARI"
107
+ expect{ word.titleize }.to_not change{ word }
108
+ end
109
+
110
+ it "upcases first character of all words" do
111
+ titleized = "merhaba çamur ismet".titleize
112
+ expect(titleized).to eq("Merhaba Çamur İsmet")
113
+ end
108
114
 
109
- it "downcases characters other than first characters of all words" do
110
- titleized = "mERHABA çAMUR iSMETOĞULLARI".titleize
111
- expect(titleized).to eq("Merhaba Çamur İsmetoğulları")
115
+ it "downcases characters other than first characters of all words" do
116
+ titleized = "mERHABA çAMUR iSMETOĞULLARI".titleize
117
+ expect(titleized).to eq("Merhaba Çamur İsmetoğulları")
118
+ end
112
119
  end
120
+
121
+ context "with destructive version" do
122
+ it "changes the original value of the string with the titleized version" do
123
+ word = "mERHABA çAMUR iSMETOĞULLARI"
124
+ expect{ word.titleize! }.to change{ word }
125
+ expect(word).to eq("Merhaba Çamur İsmetoğulları")
126
+ end
127
+ end
113
128
  end
114
129
 
115
130
  describe "#swapcase" do
@@ -133,6 +148,35 @@ module TurkishSupport
133
148
  end
134
149
  end
135
150
  end
151
+ end
152
+
153
+ describe Array do
154
+ let(:unsorted_array1) { %w(bağcılar bahçelievler şimdi çüNKÜ olmalı üç\ kere düş ılık duy) }
155
+ let(:sorted_array1) { %w(bağcılar bahçelievler çüNKÜ duy düş ılık olmalı şimdi üç\ kere) }
156
+ let(:unsorted_array2) { %w(iki üç dört ılık iğne iyne ul) }
157
+ let(:sorted_array2) { %w(dört ılık iğne iki iyne ul üç) }
136
158
 
159
+ describe "#sort" do
160
+ context "with non-destructive version" do
161
+ it "does not change the original value of the array" do
162
+ expect{ unsorted_array1.sort }.to_not change{ unsorted_array1 }
163
+ end
164
+
165
+ it "sorts array in alphabetical order" do
166
+ expect(unsorted_array1.sort).to eq(sorted_array1)
167
+ end
168
+
169
+ it "sorts array in alphabetical order" do
170
+ expect(unsorted_array2.sort).to eq(sorted_array2)
171
+ end
172
+ end
173
+
174
+ context "with destructive version" do
175
+ it "changes the original value of the array" do
176
+ expect{ unsorted_array1.sort! }.to change{ unsorted_array1 }
177
+ expect(unsorted_array1).to eq(sorted_array1)
178
+ end
179
+ end
180
+ end
137
181
  end
138
182
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turkish_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sıtkı Bağdat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-05 00:00:00.000000000 Z
11
+ date: 2014-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,14 +68,16 @@ files:
68
68
  - README.md
69
69
  - Rakefile
70
70
  - lib/turkish_support.rb
71
- - lib/turkish_support/capitalize.rb
72
- - lib/turkish_support/casecmp.rb
71
+ - lib/turkish_support/array/helpers.rb
72
+ - lib/turkish_support/array/sort.rb
73
73
  - lib/turkish_support/constants.rb
74
- - lib/turkish_support/downcase.rb
75
- - lib/turkish_support/helpers.rb
76
- - lib/turkish_support/swapcase.rb
77
- - lib/turkish_support/titleize.rb
78
- - lib/turkish_support/upcase.rb
74
+ - lib/turkish_support/string/capitalize.rb
75
+ - lib/turkish_support/string/casecmp.rb
76
+ - lib/turkish_support/string/downcase.rb
77
+ - lib/turkish_support/string/helpers.rb
78
+ - lib/turkish_support/string/swapcase.rb
79
+ - lib/turkish_support/string/titleize.rb
80
+ - lib/turkish_support/string/upcase.rb
79
81
  - lib/turkish_support/version.rb
80
82
  - spec/spec_helper.rb
81
83
  - spec/turkish_support_spec.rb
@@ -1,7 +0,0 @@
1
- module TurkishSupport
2
- refine String do
3
- def titleize
4
- self.split.map{ |w| w.downcase.capitalize }.join(' ')
5
- end
6
- end
7
- end