turkish_support 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93987885fea718401aa9d3446cb2fde4b6f48f58
4
- data.tar.gz: 7baca2da2b11b8e254e7b0a472bf487db47d4e75
3
+ metadata.gz: f3b1088be5dda40f1dc4e4eb6fbb7d38db262f00
4
+ data.tar.gz: 9c43ab7aae842e4afb6dc9e816a62d856b0741e6
5
5
  SHA512:
6
- metadata.gz: 650a0fd7c4ff78a619cdd303fe0e9d364442fd0010a3225aadbcbb0831115d9f7179646fdb72a6d1820d06c5a73da1096987ea71a71af3895fa3873913a76518
7
- data.tar.gz: 5ad930572e3b5acd91d49a9f64b35e118fca0468c92d6b18677ca7ebf9808e04a29b804a7af0eafe9b57c2a593dc4295459fc12dbe6219a972f478a132e00bff
6
+ metadata.gz: 2163bef027f543a1e6b19ffd321f6be0f1b6a758191503672e454ab149451a6270fb1a7fc74974b76090ac7f055699aa7681a14b52f7498193bce811168b1589
7
+ data.tar.gz: 28bbd4b4e070ccc06359d3e6aa6eacfef69cd4c7b808ecf8221f0f33667f3bda4e3cbd4f2e97a35457988cb85274192417c8eba87791d25e04023a4cade80345
data/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/turkish_support.svg)](http://badge.fury.io/rb/turkish_support)
4
4
  [![Build Status](https://travis-ci.org/sbagdat/turkish_support.svg?branch=master)](https://travis-ci.org/sbagdat/turkish_support)
5
+ [![Gitter chat](https://badges.gitter.im/sbagdat/turkish_support.png)](https://gitter.im/sbagdat/turkish_support)
5
6
 
6
- Turkish character support for some core ruby methods. This gem provide support for these methods: `String#upcase`,
7
- `String#downcase`, `String#capitalize`, `String#swapcase`, `String#casecmp`, `String#match`, `Array#sort`, `Array#sort!`,
8
- and their destructive versions like `String#capitalize!`. It also gives you some bonus methods like `String#titleize`.
7
+ Turkish character support for some core ruby methods. This gem provide support for those methods: `String#upcase`,
8
+ `String#downcase`, `String#capitalize`, `String#swapcase`, `String#casecmp`, `String#match`, `Array#sort`, and their destructive versions like `Array#sort!` or `String#capitalize!`. It also gives you some bonus methods like `String#titleize`.
9
9
 
10
10
  ## Requirements
11
11
 
@@ -38,7 +38,7 @@ After the installation of the gem, you should follow these steps.
38
38
  * Require the gem:
39
39
 
40
40
  ```ruby
41
- require TurkishSupport
41
+ require 'turkish_support'
42
42
  ```
43
43
 
44
44
  * Add `using TurkishSupport` line to where you want to activate it.
@@ -47,14 +47,6 @@ After the installation of the gem, you should follow these steps.
47
47
  using TurkishSupport
48
48
  ```
49
49
 
50
- Example usage on the terminal:
51
-
52
- ```ruby
53
- $ require 'turkish_support' #=> true
54
- $ using TurkishSupport #=> main
55
- $ 'içel'.upcase #=> "İÇEL"
56
- ```
57
-
58
50
  Example usage inside a class:
59
51
 
60
52
  ```ruby
@@ -1,15 +1,8 @@
1
1
  require "turkish_support/version"
2
-
3
2
  require "turkish_support/constants"
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
- require "turkish_support/string/match"
12
- require "turkish_support/array/sort"
3
+ require "turkish_support/string_helpers"
4
+ require "turkish_support/string_methods"
5
+ require "turkish_support/array_methods"
13
6
  require "turkish_support/destructives"
14
7
 
15
8
  module TurkishSupport
@@ -6,15 +6,16 @@ module TurkishSupport
6
6
  UNSUPPORTED_UPCASE_CHARS = 'ÇĞIİÖŞÜ'
7
7
  ORDERED_CHARS = UPCASED_ALPHABET + DOWNCASED_ALPHABET
8
8
 
9
- DESTRUCTIVE_STRING_METHODS = %i(capitalize downcase swapcase titleize upcase)
9
+ DESTRUCTIVE_STRING_METHODS = %i(swapcase titleize)
10
10
  DESTRUCTIVE_ARRAY_METHODS = %i(sort)
11
11
 
12
12
  MATCH_TRANSFORMATIONS = {
13
- '\w' => "[#{'\w'}#{UNSUPPORTED_DOWNCASE_CHARS}#{UNSUPPORTED_UPCASE_CHARS}]",
14
- '\W' => "[#{'^\w\d_'}#{UNSUPPORTED_DOWNCASE_CHARS}#{UNSUPPORTED_UPCASE_CHARS}]",
13
+ '\w' => '[\p{Latin}\d_]',
14
+ '\W' => '[^\p{Latin}\d_]',
15
15
  'a-z' => DOWNCASED_ALPHABET,
16
16
  'A-Z' => UPCASED_ALPHABET
17
17
  }
18
18
 
19
19
  CONJUCTIONS = %w(ve ile veya)
20
+ SPECIAL_CHARS = %(\("')
20
21
  end
@@ -1,6 +1,5 @@
1
1
  module TurkishSupport
2
2
  refine String do
3
-
4
3
  def change_chars_for_upcase
5
4
  tr UNSUPPORTED_DOWNCASE_CHARS, UNSUPPORTED_UPCASE_CHARS
6
5
  end
@@ -9,6 +8,10 @@ module TurkishSupport
9
8
  tr UNSUPPORTED_UPCASE_CHARS, UNSUPPORTED_DOWNCASE_CHARS
10
9
  end
11
10
 
11
+ def change_chars_for_capitalize
12
+ [chr.change_chars_for_upcase.send(:upcase), self[1..-1].downcase].join
13
+ end
14
+
12
15
  def unsupported_downcase?
13
16
  UNSUPPORTED_DOWNCASE_CHARS.include? chr
14
17
  end
@@ -23,7 +26,15 @@ module TurkishSupport
23
26
 
24
27
  def transform_regex
25
28
  MATCH_TRANSFORMATIONS.each { |k, v| self.gsub!(k, v) }
26
- self
29
+ self.force_encoding("UTF-8")
30
+ end
31
+
32
+ def conjuction?
33
+ CONJUCTIONS.include? self
34
+ end
35
+
36
+ def start_with_a_special_char?
37
+ self =~ /^[#{SPECIAL_CHARS}]/
27
38
  end
28
39
 
29
40
  alias_method :words, :split
@@ -0,0 +1,48 @@
1
+ module TurkishSupport
2
+ refine String do
3
+ %i{downcase downcase! upcase upcase! capitalize capitalize!}.each do |method_name|
4
+ non_destructive_method_name = method_name.to_s.chomp('!')
5
+ helper_method = instance_method("change_chars_for_#{non_destructive_method_name}")
6
+ define_method(method_name) do
7
+ str = helper_method.bind(self).call.public_send(non_destructive_method_name)
8
+ return method_name.to_s.end_with?('!') ? public_send(:replace, str) : str
9
+ end
10
+ end
11
+
12
+ def titleize(conjuctions=true)
13
+ words.map do |word|
14
+ word.downcase!
15
+ if word.conjuction? && !conjuctions
16
+ word
17
+ elsif word.start_with_a_special_char?
18
+ word.chr + word[1..-1].capitalize
19
+ else
20
+ word.capitalize
21
+ end
22
+ end.join(' ')
23
+ end
24
+
25
+ def swapcase
26
+ chars.map do |ch|
27
+ if ch.unsupported?
28
+ ch.unsupported_downcase? ? ch.upcase : ch.downcase
29
+ else
30
+ ch.public_send(:swapcase)
31
+ end
32
+ end.join
33
+ end
34
+
35
+ def casecmp(other_string)
36
+ upcase.public_send(:casecmp, other_string.upcase)
37
+ end
38
+
39
+ %i[match scan =~].each do |method_name|
40
+ define_method(method_name) do |pattern|
41
+ Regexp.new(pattern) unless pattern.kind_of? Regexp
42
+ pattern, options = pattern.source, pattern.options
43
+ pattern = Regexp.new(pattern.transform_regex, Regexp::FIXEDENCODING | options)
44
+ public_send(method_name, pattern)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module TurkishSupport
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -4,7 +4,7 @@ using TurkishSupport
4
4
  module TurkishSupport
5
5
  describe VERSION do
6
6
  it 'should have a version number' do
7
- TurkishSupport::VERSION.should_not be_nil
7
+ expect(TurkishSupport::VERSION).to_not eq(nil)
8
8
  end
9
9
  end
10
10
 
@@ -175,7 +175,7 @@ module TurkishSupport
175
175
  expect('Aşağı Ayrancı'.match(/^\w+\s\w+$/).to_s).to eq('Aşağı Ayrancı')
176
176
  end
177
177
 
178
- it "matches Turkish characters when regex include smallcase range" do
178
+ it "matches Turkish characters when regex include lowercase range" do
179
179
  expect('aüvvağğ öövvaağ'.match(/^[a-z]+\s[a-z]+$/).to_s).to eq('aüvvağğ öövvaağ')
180
180
  end
181
181
 
@@ -183,10 +183,48 @@ module TurkishSupport
183
183
  expect('BAĞCIlar'.match(/[A-Z]+/).to_s).to eq('BAĞCI')
184
184
  end
185
185
 
186
- it "doesn't match Turkish characters when regex include '\\w'" do
186
+ it "doesn't match Turkish characters when regex include '\\W'" do
187
187
  expect('Aşağı Ayrancı'.match(/\W+/).to_s).to eq(' ')
188
188
  end
189
189
  end
190
+
191
+ describe "#scan" do
192
+ it "matches Turkish characters when regex include '\\w'" do
193
+ expect(turkish_words.join(' ').scan(/\w+/)).to eq(turkish_words)
194
+ end
195
+
196
+ it "matches Turkish characters when regex include lowercase range" do
197
+ expect(turkish_words.join(' ').scan(/^[a-z\s]+$/)).to eq([turkish_words.join(' ')])
198
+ end
199
+
200
+ it "matches Turkish characters when regex include uppercase range" do
201
+ expect(turkish_words.join(' ').upcase.scan(/^[A-Z\s]+$/)).to eq([turkish_words.join(' ').upcase])
202
+ end
203
+
204
+ it "matches Turkish characters when regex include '\\w'" do
205
+ expect(turkish_words.join(' ').scan(/\W+/).map(&:strip).all?(&:empty?)).to eq(true)
206
+ end
207
+ end
208
+
209
+ describe "#=~" do
210
+ tr_chars = UNSUPPORTED_DOWNCASE_CHARS+UNSUPPORTED_UPCASE_CHARS
211
+
212
+ it "matches Turkish characters when regex include '\\w'" do
213
+ expect(tr_chars.split(//).all? {|ch| (ch =~ /\w/) == 0}).to eq(true)
214
+ end
215
+
216
+ it "matches Turkish characters when regex include lowercase range" do
217
+ expect(UNSUPPORTED_DOWNCASE_CHARS.split(//).all? {|ch| (ch =~ /[a-z]/) == 0}).to eq(true)
218
+ end
219
+
220
+ it "matches Turkish characters when regex include uppercase range" do
221
+ expect(UNSUPPORTED_UPCASE_CHARS.split(//).all? {|ch| (ch =~ /[A-Z]/) == 0}).to eq(true)
222
+ end
223
+
224
+ it "doesn't match Turkish characters when regex include '\\W'" do
225
+ expect(tr_chars.split(//).all? {|ch| (ch =~ /\W/).nil?}).to eq(true)
226
+ end
227
+ end
190
228
  end
191
229
 
192
230
  describe Array do
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.2.3
4
+ version: 0.3.0
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-05-13 00:00:00.000000000 Z
11
+ date: 2015-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,17 +68,11 @@ files:
68
68
  - README.md
69
69
  - Rakefile
70
70
  - lib/turkish_support.rb
71
- - lib/turkish_support/array/sort.rb
71
+ - lib/turkish_support/array_methods.rb
72
72
  - lib/turkish_support/constants.rb
73
73
  - lib/turkish_support/destructives.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/match.rb
79
- - lib/turkish_support/string/swapcase.rb
80
- - lib/turkish_support/string/titleize.rb
81
- - lib/turkish_support/string/upcase.rb
74
+ - lib/turkish_support/string_helpers.rb
75
+ - lib/turkish_support/string_methods.rb
82
76
  - lib/turkish_support/version.rb
83
77
  - spec/spec_helper.rb
84
78
  - spec/turkish_support_spec.rb
@@ -103,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
97
  version: '0'
104
98
  requirements: []
105
99
  rubyforge_project:
106
- rubygems_version: 2.2.2
100
+ rubygems_version: 2.4.5
107
101
  signing_key:
108
102
  specification_version: 4
109
103
  summary: Turkish character support for some core ruby methods.
@@ -1,7 +0,0 @@
1
- module TurkishSupport
2
- refine String do
3
- def capitalize
4
- [chr.change_chars_for_upcase.send(:upcase), self[1..-1].downcase].join
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module TurkishSupport
2
- refine String do
3
- def casecmp(other_string)
4
- upcase.send(:casecmp, other_string.upcase)
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module TurkishSupport
2
- refine String do
3
- def downcase
4
- change_chars_for_downcase.send(:downcase)
5
- end
6
- end
7
- end
@@ -1,11 +0,0 @@
1
- module TurkishSupport
2
- refine String do
3
- def match(pattern)
4
- if pattern.kind_of? Regexp
5
- pattern = pattern.inspect[1...-1]
6
- pattern = Regexp.new(pattern.transform_regex)
7
- end
8
- send(:match, pattern)
9
- end
10
- end
11
- end
@@ -1,13 +0,0 @@
1
- module TurkishSupport
2
- refine String do
3
- def swapcase
4
- chars.map do |ch|
5
- if ch.unsupported?
6
- ch.unsupported_downcase? ? ch.upcase : ch.downcase
7
- else
8
- ch.send(:swapcase)
9
- end
10
- end.join
11
- end
12
- end
13
- end
@@ -1,16 +0,0 @@
1
- module TurkishSupport
2
- refine String do
3
- def titleize(conjuctions=true)
4
- words.map do |w|
5
- w.downcase!
6
- if CONJUCTIONS.include?(w) && !conjuctions
7
- w
8
- elsif w =~ /^[\("']/
9
- w[0] + w[1..-1].capitalize
10
- else
11
- w.capitalize
12
- end
13
- end.join(' ')
14
- end
15
- end
16
- end
@@ -1,7 +0,0 @@
1
- module TurkishSupport
2
- refine String do
3
- def upcase
4
- change_chars_for_upcase.send(:upcase)
5
- end
6
- end
7
- end