turkish_support 0.0.1 → 0.0.2

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: 40ad8f5d403b52ed781cecd0c82a31affb500c7f
4
- data.tar.gz: 185772d61857b0e9273f5828d9685c904f1c3c1e
3
+ metadata.gz: 05f59d2e23f979fa67a13e40f3598ba4ae25b506
4
+ data.tar.gz: 8ed7a3d8e73838c1ae6cace4f44be2713e11ceda
5
5
  SHA512:
6
- metadata.gz: 3b46397b5cce71b37ba11a830f2cef022d723c1e898bc148090695b83c3fd1290e57a08515a1e22756d160e6d4e8b4bfdf6ac33dbf89edeaa1dfd6c18ca2fd05
7
- data.tar.gz: 62cd6b1146984403134cb4cf0cdf1dd6edc2762b1e215379fe2260e8e8df2d905ee34dd7937d908bc7c5a3c77a1e02b640e4cab35d2afc4f6a67b0a4461e608f
6
+ metadata.gz: 28cd46ba32f30d61acbca5fd689603ea41310bd15d1df62dfb9ad81b60bc8b6089186620a032ac710485a97d2d36f6972e307aaea423feaeb51edf3d6496e26c
7
+ data.tar.gz: f755fb7dfec1191963a7ed822ccb95aff7c3cfc377a7644fd54b3074ee2fbc25a9383313652bd43853049b74e5e9231ab2d5693f0be546a68ffd588953868c0c
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # TurkishSupport
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/turkish_support.svg)](http://badge.fury.io/rb/turkish_support)
4
+
5
+
3
6
  A gem for Turkish character support for `String#upcase`, `String#downcase`, `String#capitalize` methods and their destructive versions like `String#upcase!`. In other words; this gem is a lighter version of the UnicodeUtils gem.
4
7
 
5
8
  ## Requirements
@@ -27,6 +30,8 @@ After installing the gem, you want to add a line before using Turkish supported
27
30
  using TurkishSupport
28
31
  ```
29
32
 
33
+ If you want to see a simple [gist](https://gist.github.com/sbagdat/9964521) that shows how should you use it.
34
+
30
35
  Now you can use your shiny new methods like below:
31
36
 
32
37
  ```ruby
@@ -1,42 +1,9 @@
1
1
  require "turkish_support/version"
2
+ 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"
2
9
 
3
- module TurkishSupport
4
- UNSUPPORTED_CHARS = {
5
- downcase: 'çğıiöşü',
6
- upcase: 'ÇĞIİÖŞÜ'
7
- }
8
-
9
- refine String do
10
- def change_chars_for_upcase
11
- tr UNSUPPORTED_CHARS[:downcase], UNSUPPORTED_CHARS[:upcase]
12
- end
13
-
14
- def change_chars_for_downcase
15
- tr UNSUPPORTED_CHARS[:upcase], UNSUPPORTED_CHARS[:downcase]
16
- end
17
-
18
- def upcase
19
- change_chars_for_upcase.send(:upcase)
20
- end
21
-
22
- def upcase!
23
- replace(upcase)
24
- end
25
-
26
- def downcase
27
- change_chars_for_downcase.send(:downcase)
28
- end
29
-
30
- def downcase!
31
- replace(downcase)
32
- end
33
-
34
- def capitalize
35
- [self[0].change_chars_for_upcase.send(:upcase), self[1..-1]].join
36
- end
37
-
38
- def capitalize!
39
- replace(capitalize)
40
- end
41
- end
42
- end
@@ -0,0 +1,11 @@
1
+ module TurkishSupport
2
+ refine String do
3
+ def capitalize
4
+ [self[0].change_chars_for_upcase.send(:upcase), self[1..-1]].join
5
+ end
6
+
7
+ def capitalize!
8
+ replace(capitalize)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
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
@@ -0,0 +1,4 @@
1
+ UNSUPPORTED_CHARS = {
2
+ downcase: 'çğıiöşü',
3
+ upcase: 'ÇĞIİÖŞÜ'
4
+ }
@@ -0,0 +1,11 @@
1
+ module TurkishSupport
2
+ refine String do
3
+ def downcase
4
+ change_chars_for_downcase.send(:downcase)
5
+ end
6
+
7
+ def downcase!
8
+ replace(downcase)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module TurkishSupport
2
+ refine String do
3
+ def change_chars_for_upcase
4
+ tr UNSUPPORTED_CHARS[:downcase], UNSUPPORTED_CHARS[:upcase]
5
+ end
6
+
7
+ def change_chars_for_downcase
8
+ tr UNSUPPORTED_CHARS[:upcase], UNSUPPORTED_CHARS[:downcase]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module TurkishSupport
2
+ refine String do
3
+ def titleize
4
+ self.split.map{ |w| w.capitalize }.join(' ')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module TurkishSupport
2
+ refine String do
3
+ def upcase
4
+ change_chars_for_upcase.send(:upcase)
5
+ end
6
+
7
+ def upcase!
8
+ replace(upcase)
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module TurkishSupport
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,2 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'turkish_support'
3
-
@@ -1,97 +1,115 @@
1
1
  require 'spec_helper'
2
2
 
3
- include TurkishSupport
4
- using TurkishSupport
3
+ module TurkishSupport
5
4
 
6
- describe TurkishSupport do
7
- it 'should have a version number' do
8
- TurkishSupport::VERSION.should_not be_nil
5
+ describe VERSION do
6
+ it 'should have a version number' do
7
+ TurkishSupport::VERSION.should_not be_nil
8
+ end
9
9
  end
10
10
 
11
- describe "#upcase" do
12
- context "with non-destructive version" do
13
- it "does not change the original value of the string" do
14
- turkish_alphabet = "abcçdefgğhıijklmnoöprsştuüvyz"
15
- expect{ turkish_alphabet.upcase }.to_not change{ turkish_alphabet }
16
- end
11
+ describe String do
12
+ using TurkishSupport
17
13
 
18
- it "upcases all of Turkish characters" do
19
- turkish_alphabet = "abcçdefgğhıijklmnoöprsştuüvyz"
20
- upcased_string = turkish_alphabet.upcase
21
- expect(upcased_string).to eq("ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ")
22
- end
14
+ let(:downcased_turkish_alphabet) { "abcçdefgğhıijklmnoöprsştuüvyz" }
15
+ let(:upcased_turkish_alphabet) { "ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ" }
16
+ let(:downcased_english_alphabet) { [*'a'..'z'].join }
17
+ let(:upcased_english_alphabet) { [*'A'..'Z'].join }
18
+ let(:turkish_words) { %w(çamur ıhlamur insan ördek şahika ümraniye) }
19
+
20
+ describe "#upcase" do
21
+ context "with non-destructive version" do
22
+ it "does not change the original value of the string" do
23
+ expect{ downcased_turkish_alphabet.upcase }.to_not change{ downcased_turkish_alphabet }
24
+ end
25
+
26
+ it "upcases all of Turkish characters" do
27
+ upcased_string = downcased_turkish_alphabet.upcase
28
+ expect(upcased_string).to eq( upcased_turkish_alphabet )
29
+ end
23
30
 
24
- it "upcases English characters except i as I" do
25
- english_alphabet = "abcdefghijklmnopqrstuvwxyz"
26
- upcased_string = english_alphabet.upcase
27
- expect(upcased_string).to eq("ABCDEFGHİJKLMNOPQRSTUVWXYZ")
31
+ it "upcases English characters except i as I" do
32
+ upcased_string = downcased_english_alphabet.upcase
33
+ expect(upcased_string).to eq( upcased_english_alphabet.tr('I', 'İ'))
34
+ end
28
35
  end
29
- end
30
36
 
31
- context "with destructive version" do
32
- it "changes the original value of the string with the upcased version" do
33
- turkish_alphabet = "abcçdefgğhıijklmnoöprsştuüvyz"
34
- expect{ turkish_alphabet.upcase! }.to change{ turkish_alphabet }
35
- expect(turkish_alphabet).to eq("ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ")
37
+ context "with destructive version" do
38
+ it "changes the original value of the string with the upcased version" do
39
+ expect{ downcased_turkish_alphabet.upcase! }.to change{ downcased_turkish_alphabet }
40
+ expect( downcased_turkish_alphabet).to eq( upcased_turkish_alphabet )
41
+ end
36
42
  end
37
43
  end
38
- end
39
44
 
40
- describe "#downcase" do
41
- context "with non-destructive version" do
42
- it "does not change the original value of the string" do
43
- turkish_alphabet = "ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ"
44
- expect{ turkish_alphabet.downcase }.to_not change{ turkish_alphabet }
45
- end
45
+ describe "#downcase" do
46
+ context "with non-destructive version" do
47
+ it "does not change the original value of the string" do
48
+ expect{ upcased_turkish_alphabet.downcase }.to_not change{ upcased_turkish_alphabet }
49
+ end
46
50
 
47
- it "downcases all of Turkish characters" do
48
- turkish_alphabet = "ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ"
49
- downcased_string = turkish_alphabet.downcase
50
- expect(downcased_string).to eq("abcçdefgğhıijklmnoöprsştuüvyz")
51
- end
51
+ it "downcases all of Turkish characters" do
52
+ downcased_string = upcased_turkish_alphabet.downcase
53
+ expect(downcased_string).to eq( downcased_turkish_alphabet )
54
+ end
52
55
 
53
- it "downcases English characters except I as ı" do
54
- english_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
55
- downcased_string = english_alphabet.downcase
56
- expect(downcased_string).to eq("abcdefghıjklmnopqrstuvwxyz")
56
+ it "downcases English characters except I as ı" do
57
+ downcased_string = upcased_english_alphabet.downcase
58
+ expect(downcased_string).to eq( downcased_english_alphabet.tr('i', 'ı'))
59
+ end
57
60
  end
58
- end
59
61
 
60
- context "with destructive version" do
61
- it "changes the original value of the string with the downcased version" do
62
- turkish_alphabet = "ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ"
63
- expect{ turkish_alphabet.downcase! }.to change{ turkish_alphabet }
64
- expect(turkish_alphabet).to eq("abcçdefgğhıijklmnoöprsştuüvyz")
62
+ context "with destructive version" do
63
+ it "changes the original value of the string with the downcased version" do
64
+ expect{ upcased_turkish_alphabet.downcase! }.to change{ upcased_turkish_alphabet }
65
+ expect( upcased_turkish_alphabet).to eq(downcased_turkish_alphabet)
66
+ end
65
67
  end
66
68
  end
67
- end
68
69
 
69
- describe "#capitalize" do
70
- context "with non-destructive version" do
71
- it "does not change the original value of the string" do
72
- turkish_word = "çamur"
73
- expect{ turkish_word.capitalize }.to_not change{ turkish_word }
70
+ describe "#capitalize" do
71
+ context "with non-destructive version" do
72
+ it "does not change the original value of the string" do
73
+ turkish_word = turkish_words.sample
74
+ expect{ turkish_word.capitalize }.to_not change{ turkish_word }
75
+ end
76
+
77
+ it "capitalizes the first character of a string that starts with an unsupported Turkish character" do
78
+ capitalized_words = turkish_words.map{ |w| w.capitalize }
79
+ expect(capitalized_words).to eq(%w[Çamur Ihlamur İnsan Ördek Şahika Ümraniye])
80
+ end
81
+
82
+ it "capitalizes the first character of an English string" do
83
+ english_word = "spy"
84
+ capitalized_string = english_word.capitalize
85
+ expect(capitalized_string).to eq("Spy")
86
+ end
74
87
  end
75
88
 
76
- it "capitalizes the first character of a string that starts with an unsupported Turkish character" do
77
- turkish_words = %w[çamur ıhlamur insan ördek şahika ümraniye]
78
- capitalized_words = turkish_words.map{ |w| w.capitalize }
79
- expect(capitalized_words).to eq(%w[Çamur Ihlamur İnsan Ördek Şahika Ümraniye])
89
+ context "with destructive version" do
90
+ it "changes the original value of the string with the capitalized version" do
91
+ turkish_word = 'çamur'
92
+ expect{ turkish_word.capitalize! }.to change{ turkish_word }
93
+ expect(turkish_word).to eq('Çamur')
94
+ end
80
95
  end
96
+ end
81
97
 
82
- it "capitalizes the first character of an English string" do
83
- english_word = "spy"
84
- capitalized_string = english_word.capitalize
85
- expect(capitalized_string).to eq("Spy")
98
+ describe "#casecmp" do
99
+ it "compares Turkish characters correctly" do
100
+ result = downcased_turkish_alphabet.casecmp(upcased_turkish_alphabet)
101
+ expect(result).to be_zero
86
102
  end
87
103
  end
88
104
 
89
- context "with destructive version" do
90
- it "changes the original value of the string with the capitalized version" do
91
- turkish_word = 'çamur'
92
- expect{ turkish_word.capitalize! }.to change{ turkish_word }
93
- expect(turkish_word).to eq('Çamur')
105
+ describe "#titleize" do
106
+ it "capitalizes first character of all words" do
107
+ titleized = "merhaba çamur ismet".titleize
108
+ expect(titleized).to eq("Merhaba Çamur İsmet")
94
109
  end
95
110
  end
96
111
  end
97
112
  end
113
+
114
+
115
+
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.0.1
4
+ version: 0.0.2
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-03 00:00:00.000000000 Z
11
+ date: 2014-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,6 +69,13 @@ files:
69
69
  - README.md
70
70
  - Rakefile
71
71
  - lib/turkish_support.rb
72
+ - lib/turkish_support/capitalize.rb
73
+ - lib/turkish_support/casecmp.rb
74
+ - lib/turkish_support/constants.rb
75
+ - lib/turkish_support/downcase.rb
76
+ - lib/turkish_support/helpers.rb
77
+ - lib/turkish_support/titleize.rb
78
+ - lib/turkish_support/upcase.rb
72
79
  - lib/turkish_support/version.rb
73
80
  - spec/spec_helper.rb
74
81
  - spec/turkish_support_spec.rb