turkish_support 0.1.2 → 0.2.0

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: cfd15f4f58e479f52c15d1a7b2e780534929305f
4
- data.tar.gz: 6f88ae7c91ec474ab49864d1d8de5bc60549b9ab
3
+ metadata.gz: e462ea6658063408935a25bab7ac3ec2b4b2ec30
4
+ data.tar.gz: 3067e7df0ac8d20abe546c1ef2c2b11341f7bd83
5
5
  SHA512:
6
- metadata.gz: 047dfa3fc477b0aea9c1429d64d5623a886189e2e900bf51622a367a9dcc7249a967838c12082f64a93f81c69c454eae69c812a51097d58ea5ca9f0cac0dff71
7
- data.tar.gz: ba18883f0898f891a4aa80ad13ecf7c764755fa2603a3e38efa46d91721d5ed086015394a93a5889e3e472bcc172c67ddc635b643b7d0560b8019a05082aaff8
6
+ metadata.gz: ce620744b8b42db62a4dbb7b8d4cb0694145d18d3fc632a431f06479f2e8b9c85c7ef738627f0ebb211c701723caf0a581f6f2e2c0d9ee237b56bb014c53a200
7
+ data.tar.gz: 052a5c8edc082be0282c6412413cae98fddcf075f998ffffb346ed7d0efce472988b12ac44735a2b4f6139ca6bee310a3411400ef8dd16447858841f03ff4f67
data/README.md CHANGED
@@ -3,22 +3,9 @@
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
5
 
6
- Turkish character support for some standard Ruby methods. This gem provide support for these methods:
7
- * `String#upcase`
8
- * `String#upcase!`
9
- * `String#downcase`
10
- * `String#downcase!`
11
- * `String#capitalize`
12
- * `String#capitalize!`
13
- * `String#swapcase`
14
- * `String#swapcase!`
15
- * `String#casecmp`
16
- * `Array#sort`
17
- * `Array#sort!`
18
-
19
- Also gives you some new methods like:
20
- * `String#titleize`
21
- * `String#titleize!`
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`.
22
9
 
23
10
  ## Requirements
24
11
 
@@ -46,46 +33,129 @@ Or install it yourself as:
46
33
 
47
34
  After the installation of the gem, you should follow these steps.
48
35
 
49
- * You need require it.
36
+ ### Using with ruby
50
37
 
51
- __Note:__ If you are using a framework like Rails, you don't need to require, because it is already required by the framework.
38
+ * Require the gem:
52
39
 
53
40
  ```ruby
54
41
  require TurkishSupport
55
42
  ```
56
43
 
57
- * Add `using TurkishSupport` line to the top of the scope, __not inside of any class or module__.
44
+ * Add `using TurkishSupport` line to where you want to activate it.
58
45
 
59
46
  ```ruby
60
- using TurkishSupport
47
+ using TurkishSupport
48
+ ```
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
+ Example usage inside a class:
59
+
60
+ ```ruby
61
+ require 'turkish_support'
62
+
63
+ class Test
64
+ using TurkishSupport
65
+ def up_me(str)
66
+ str.upcase
67
+ end
68
+ end
69
+
70
+ Test.new.up_me('içel') #=> "İÇEL"
71
+ ```
72
+
73
+ ### Using with rails
74
+
75
+ __Note:__ You don't need to require, because it is already required by the rails.
76
+
77
+ * In rails you must add `using TurkishSupport` line to the top of the scope, __not inside of any class or module__.
78
+
79
+ ```ruby
80
+ using TurkishSupport
81
+
82
+ class SampleModel
83
+ ...
84
+ end
61
85
  ```
62
86
 
63
87
  ## Examples
64
88
 
65
- Within the file which you added `using TurkishSupport` line to the top of the scope; you can use core methods like below:
89
+ Within the file that you added `using TurkishSupport` line; you can use the core methods like below:
90
+
91
+ __String#upcase__ and __String#upcase!__
66
92
 
67
93
  ```ruby
68
94
  str = 'Bağcılar'
69
- str.upcase #=> "BAĞCILAR"
70
- str #=> "Bağcılar"
71
95
 
72
- str = "İSMAİL"
73
- str.downcase! #=> "ismail"
74
- str #=> "ismail"
96
+ str.upcase #=> "BAĞCILAR"
97
+ str #=> "Bağcılar"
75
98
 
76
- "merhaba".capitalize #=> "Merhaba"
99
+ str.upcase! #=> "BAĞCILAR"
100
+ str #=> "BAĞCILAR"
101
+ ```
102
+
103
+ __String#downcase__ and __String#downcase!__
77
104
 
78
- ["iki", "üç", "dört", "ılık", "iğne", "iyne"].sort #=> ["dört", "ılık", "iğne", "iki", "iyne", "üç"]
105
+ ```ruby
106
+ str = 'İSMAİL'
107
+ str.downcase #=> "ismail"
79
108
  ```
80
109
 
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:
110
+ __String#capitalize__ and __String#capitalize!__
111
+
112
+ ```ruby
113
+ str = 'türkÇE desteĞİ'
114
+ str.capitalize #=> "Türkçe desteği"
115
+ ```
116
+
117
+ __String#swapcase__ and __String#swapcase!__
118
+ ```ruby
119
+ 'TuğÇE'.swapcase #=> "tUĞçe"
120
+ ```
121
+
122
+ __String#casecmp__
123
+ ```ruby
124
+ 'sıtKI'.casecmp('SITkı') #=> 0
125
+ ```
126
+
127
+ __String#match__
128
+
129
+ ```ruby
130
+ 'Aşağı'.match(/\w+/) #=> #<MatchData "Aşağı">
131
+ 'Aşağı Ayrancı'.match(/^\w+\s\w+$/) #=> #<MatchData "Aşağı Ayrancı">
132
+ 'aüvvağğ öövvaağ'.match(/^[a-z]+\s[a-z]+$/) #=> #<MatchData "aüvvağğ öövvaağ">
133
+ 'BAĞCIlar'.match(/[A-Z]+/) #=> #<MatchData "BAĞCI">
134
+ 'Aşağı Ayrancı'.match(/\W+/) #=> #<MatchData "">
135
+ ```
136
+
137
+ __Array#sort__ and __Array#sort!__
138
+
139
+ ```ruby
140
+ %w(iki üç dört ılık iğne iyne).sort
141
+ #=> ["dört", "ılık", "iğne", "iki", "iyne", "üç"]
142
+ ```
143
+
144
+ __String#titleize__ and __String#titleize!__
145
+
146
+ These methods are not core methods of ruby, but they are accepted as useful in most situation.
147
+
148
+ ```ruby
149
+ 'türkÇE desteĞİ'.titleize #=> "Türkçe Desteği"
150
+ ```
151
+
152
+ __Important Note:__ If you also want to use original set of the core methods in the same scope, you can use `send` method like this:
82
153
 
83
154
  ```ruby
84
155
  str = 'Bağcılar'
85
156
  str.send(:upcase) #=> "BAğCıLAR"
86
157
  ```
87
158
 
88
-
89
159
  ## Contributing
90
160
 
91
161
  1. Fork it ( http://github.com/sbagdat/turkish_support/fork )
@@ -1,6 +1,6 @@
1
- require "turkish_support/constants"
2
1
  require "turkish_support/version"
3
2
 
3
+ require "turkish_support/constants"
4
4
  require "turkish_support/string/helpers"
5
5
  require "turkish_support/string/upcase"
6
6
  require "turkish_support/string/downcase"
@@ -8,9 +8,8 @@ require "turkish_support/string/capitalize"
8
8
  require "turkish_support/string/titleize"
9
9
  require "turkish_support/string/casecmp"
10
10
  require "turkish_support/string/swapcase"
11
-
11
+ require "turkish_support/string/match"
12
12
  require "turkish_support/array/sort"
13
-
14
13
  require "turkish_support/destructives"
15
14
 
16
15
  module TurkishSupport
@@ -8,4 +8,11 @@ module TurkishSupport
8
8
 
9
9
  DESTRUCTIVE_STRING_METHODS = %i(capitalize downcase swapcase titleize upcase)
10
10
  DESTRUCTIVE_ARRAY_METHODS = %i(sort)
11
+
12
+ MATCH_TRANSFORMATIONS = {
13
+ '\w' => "[#{'\w'}#{UNSUPPORTED_DOWNCASE_CHARS}#{UNSUPPORTED_UPCASE_CHARS}]",
14
+ '\W' => "[#{'^\w\d_'}#{UNSUPPORTED_DOWNCASE_CHARS}#{UNSUPPORTED_UPCASE_CHARS}]",
15
+ 'a-z' => DOWNCASED_ALPHABET,
16
+ 'A-Z' => UPCASED_ALPHABET
17
+ }
11
18
  end
@@ -1,7 +1,7 @@
1
1
  module TurkishSupport
2
2
  refine String do
3
3
  def capitalize
4
- [chr.change_chars_for_upcase.send(:upcase), self[1..-1]].join
4
+ [chr.change_chars_for_upcase.send(:upcase), self[1..-1].downcase].join
5
5
  end
6
6
  end
7
7
  end
@@ -21,6 +21,11 @@ module TurkishSupport
21
21
  unsupported_upcase? or unsupported_downcase?
22
22
  end
23
23
 
24
+ def transform_regex
25
+ MATCH_TRANSFORMATIONS.each { |k, v| self.gsub!(k, v) }
26
+ self
27
+ end
28
+
24
29
  alias_method :words, :split
25
30
  end
26
31
  end
@@ -0,0 +1,11 @@
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,3 +1,3 @@
1
1
  module TurkishSupport
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -77,6 +77,11 @@ module TurkishSupport
77
77
  expect(capitalized_words).to eq(%w[Çamur Ihlamur İnsan Ördek Şahika Ümraniye])
78
78
  end
79
79
 
80
+ it "capitalizes the first character of a string and downcase others" do
81
+ capitalized_words = turkish_words.map{ |w| w.capitalize }
82
+ expect('türkÇE desteĞİ'.capitalize).to eq('Türkçe desteği')
83
+ end
84
+
80
85
  it "capitalizes the first character of an English string" do
81
86
  english_word = "spy"
82
87
  capitalized_string = english_word.capitalize
@@ -98,6 +103,11 @@ module TurkishSupport
98
103
  result = downcased_turkish_alphabet.casecmp(upcased_turkish_alphabet)
99
104
  expect(result).to be_zero
100
105
  end
106
+
107
+ it "compares Turkish characters correctly" do
108
+ result = downcased_turkish_alphabet.casecmp(upcased_turkish_alphabet)
109
+ expect('sıtkı'.casecmp('SıTKI')).to eq(0)
110
+ end
101
111
  end
102
112
 
103
113
  describe "#titleize" do
@@ -148,6 +158,25 @@ module TurkishSupport
148
158
  end
149
159
  end
150
160
  end
161
+
162
+ describe "#match" do
163
+ it "matches Turkish characters when regex include '\\w'" do
164
+ expect('Aşağı'.match(/\w+/).to_s).to eq('Aşağı')
165
+ expect('Aşağı Ayrancı'.match(/^\w+\s\w+$/).to_s).to eq('Aşağı Ayrancı')
166
+ end
167
+
168
+ it "matches Turkish characters when regex include smallcase range" do
169
+ expect('aüvvağğ öövvaağ'.match(/^[a-z]+\s[a-z]+$/).to_s).to eq('aüvvağğ öövvaağ')
170
+ end
171
+
172
+ it "matches Turkish characters when regex include uppercase range" do
173
+ expect('BAĞCIlar'.match(/[A-Z]+/).to_s).to eq('BAĞCI')
174
+ end
175
+
176
+ it "doesn't match Turkish characters when regex include '\\w'" do
177
+ expect('Aşağı Ayrancı'.match(/\W+/).to_s).to eq(' ')
178
+ end
179
+ end
151
180
  end
152
181
 
153
182
  describe Array do
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = TurkishSupport::VERSION
9
9
  spec.authors = ["Sıtkı Bağdat"]
10
10
  spec.email = ["sbagdat@gmail.com"]
11
- spec.summary = %q{Turkish character support for some standard Ruby methods.}
12
- spec.description = %q{Turkish character support for some standard Ruby methods like #upcase, #downcase, etc. Also provide some new useful methods like #titleize.}
11
+ spec.summary = %q{Turkish character support for some core ruby methods.}
12
+ spec.description = %q{Turkish character support for some core ruby methods like String#upcase, String#downcase, String#match, Array#sort, and etc...}
13
13
  spec.homepage = "https://github.com/sbagdat/turkish_support"
14
14
  spec.license = "MIT"
15
15
 
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.2
4
+ version: 0.2.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-04-06 00:00:00.000000000 Z
11
+ date: 2014-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,8 +52,8 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: 'Turkish character support for some standard Ruby methods like #upcase,
56
- #downcase, etc. Also provide some new useful methods like #titleize.'
55
+ description: Turkish character support for some core ruby methods like String#upcase,
56
+ String#downcase, String#match, Array#sort, and etc...
57
57
  email:
58
58
  - sbagdat@gmail.com
59
59
  executables: []
@@ -76,6 +76,7 @@ files:
76
76
  - lib/turkish_support/string/destructives.rb
77
77
  - lib/turkish_support/string/downcase.rb
78
78
  - lib/turkish_support/string/helpers.rb
79
+ - lib/turkish_support/string/match.rb
79
80
  - lib/turkish_support/string/swapcase.rb
80
81
  - lib/turkish_support/string/titleize.rb
81
82
  - lib/turkish_support/string/upcase.rb
@@ -106,7 +107,7 @@ rubyforge_project:
106
107
  rubygems_version: 2.2.2
107
108
  signing_key:
108
109
  specification_version: 4
109
- summary: Turkish character support for some standard Ruby methods.
110
+ summary: Turkish character support for some core ruby methods.
110
111
  test_files:
111
112
  - spec/spec_helper.rb
112
113
  - spec/turkish_support_spec.rb