turkish_support 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.reek.yml +8 -0
- data/.rspec +1 -0
- data/.rubocop.yml +8 -5
- data/CHANGELOG.md +6 -0
- data/Gemfile +3 -2
- data/README.md +50 -64
- data/Rakefile +8 -0
- data/lib/turkish_support.rb +32 -2
- data/lib/turkish_support/array_methods.rb +6 -9
- data/lib/turkish_support/constants.rb +26 -34
- data/lib/turkish_support/string_methods.rb +30 -48
- data/lib/turkish_support/version.rb +3 -1
- data/spec/array_spec.rb +57 -86
- data/spec/spec_helper.rb +3 -1
- data/spec/string_spec.rb +89 -37
- data/spec/turkish_support_spec.rb +2 -1
- data/turkish_support.gemspec +9 -2
- metadata +60 -11
- data/lib/turkish_support/helpers.rb +0 -90
- data/spec/helpers_spec.rb +0 -165
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e52aee159fcb443687f4d18c2dd77181c0bf4633dc4cdc38a123a8d8522e8865
|
4
|
+
data.tar.gz: 6e4c1d6ee4ac28d67eaef74df372dd6fc14bf1bdde81555008a24295ce21363e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b597463d4655ad862c8ba64c0c9020c543b4a85ea606acefb350f8c03164caa2395a1a06b77963c660fe9fb765f15c447e94272a95b722fc6a84c916f7f77d93
|
7
|
+
data.tar.gz: 863aefb578b72b6cee9380c53b13f5ccb275263dd52a846c8afe4647c25448642dca816ce3f762809dffa9e0b9ffb3660a645c569b506025afa491fc294830c8
|
data/.reek.yml
ADDED
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 2.7
|
3
|
-
|
4
|
-
|
5
|
-
Documentation:
|
6
|
-
Enabled: false
|
7
|
-
DotPosition:
|
3
|
+
NewCops: enable
|
4
|
+
Layout/DotPosition:
|
8
5
|
EnforcedStyle: leading
|
9
6
|
Enabled: true
|
10
7
|
Metrics/BlockLength:
|
11
8
|
ExcludedMethods: ['describe', 'context']
|
9
|
+
Style/Documentation:
|
10
|
+
Enabled: false
|
11
|
+
Style/StringLiterals:
|
12
|
+
EnforcedStyle: single_quotes
|
13
|
+
Style/AsciiComments:
|
14
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
# Changelog
|
2
|
+
## [Version 2.1.0](https://github.com/sbagdat/turkish_support/releases/tag/v2.1.0) (2020-11-25)
|
3
|
+
### Changed
|
4
|
+
- Helpers module extracted into two seperate gems (turkish_ranges, turkish_regexps). [`a2a6261`](https://github.com/sbagdat/turkish_support/commit/a2a6261)
|
5
|
+
- Too much refactoring. [`a2a6261`](https://github.com/sbagdat/turkish_support/commit/a2a6261)
|
6
|
+
- Decided to keep a changelog file (this file).
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,24 +1,23 @@
|
|
1
|
-
# TurkishSupport
|
1
|
+
# TurkishSupport [![Gem Version](https://badge.fury.io/rb/turkish_support.svg)](https://badge.fury.io/rb/turkish_support) [![Build Status](https://travis-ci.org/sbagdat/turkish_support.svg?branch=master)](https://travis-ci.org/sbagdat/turkish_support) [![Code Climate](https://codeclimate.com/github/sbagdat/turkish_support/badges/gpa.svg)](https://codeclimate.com/github/sbagdat/turkish_support)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
Turkish character support for core ruby methods. This gem provides support nearly all `String` methods, such as `String#upcase`, `String#downcase`, `String#match`, `String#gsub`. It also provides support for `Array#sort`and some bonus methods like `String#titleize`.
|
3
|
+
Turkish character support for core ruby methods. This gem provides support nearly all `String` methods,
|
4
|
+
such as `String#split`, `String#match`, `String#gsub`. It also provides support for `Array#sort`and some
|
5
|
+
bonus methods like `String#titleize`.
|
7
6
|
|
8
7
|
## Requirements
|
9
|
-
|
10
8
|
* Ruby >= 2.7.0
|
11
9
|
* Rails >= 6.0.0
|
12
10
|
|
13
|
-
__Notice:__ TurkishSupport uses __refinements__ instead of monkey patching.
|
14
|
-
|
15
11
|
* [Installation](#installation)
|
16
12
|
* [Usage](#usage)
|
17
13
|
* [Using with ruby](#using-with-ruby)
|
18
14
|
* [Using with ruby on rails](#using-with-ruby-on-rails)
|
19
|
-
* [Using Core Methods](#using-core-methods)
|
20
15
|
* [String Methods](#string-methods)
|
21
16
|
* [#<=>](#-spaceship)
|
17
|
+
* [#>](#----comparisons)
|
18
|
+
* [#>=](#----comparisons)
|
19
|
+
* [#<](#----comparisons)
|
20
|
+
* [#<=](#----comparisons)
|
22
21
|
* [#[] and #[]=](#-and-)
|
23
22
|
* [capitalize](#capitalize-and-capitalize)
|
24
23
|
* [casecmp](#casecmp)
|
@@ -39,20 +38,24 @@ __Notice:__ TurkishSupport uses __refinements__ instead of monkey patching.
|
|
39
38
|
* [Array Methods](#array-methods)
|
40
39
|
* [sort](#sort-and-sort)
|
41
40
|
|
42
|
-
|
43
41
|
## Installation
|
44
|
-
|
45
42
|
Add this line to your application's Gemfile:
|
46
43
|
|
47
|
-
|
44
|
+
```
|
45
|
+
gem 'turkish_support'
|
46
|
+
```
|
48
47
|
|
49
48
|
And then execute:
|
50
49
|
|
51
|
-
|
50
|
+
```
|
51
|
+
$ bundle
|
52
|
+
```
|
52
53
|
|
53
54
|
Or install it yourself as:
|
54
55
|
|
55
|
-
|
56
|
+
```
|
57
|
+
$ gem install turkish_support
|
58
|
+
```
|
56
59
|
|
57
60
|
## Usage
|
58
61
|
|
@@ -66,25 +69,23 @@ After the installation of the gem, you should follow these steps.
|
|
66
69
|
require 'turkish_support'
|
67
70
|
```
|
68
71
|
|
69
|
-
* Add `using TurkishSupport` line to
|
70
|
-
|
71
|
-
```ruby
|
72
|
-
using TurkishSupport
|
73
|
-
```
|
72
|
+
* Add `using TurkishSupport` line to a class or a module.
|
74
73
|
|
75
74
|
Example usage inside a class:
|
76
75
|
|
77
76
|
```ruby
|
78
77
|
require 'turkish_support'
|
79
78
|
|
80
|
-
class
|
79
|
+
class CanSpeakInTurkish
|
81
80
|
using TurkishSupport
|
82
|
-
|
83
|
-
|
81
|
+
|
82
|
+
def split_me_up(string, sep)
|
83
|
+
string.split(sep)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
|
87
|
+
CanSpeakInTurkish.new.split_me_up('çar çarı çarşı', 'ç')
|
88
|
+
# ['ar', 'arı', 'arşı']
|
88
89
|
```
|
89
90
|
|
90
91
|
### Using with ruby on rails
|
@@ -96,30 +97,22 @@ __Note:__ You don't need to require, because it is already required by the rails
|
|
96
97
|
```ruby
|
97
98
|
using TurkishSupport
|
98
99
|
|
99
|
-
class
|
100
|
-
|
100
|
+
class TopModel < ApplicationRecord
|
101
|
+
# your code goes here
|
101
102
|
end
|
102
103
|
```
|
103
104
|
|
104
|
-
* If you want to use TurkishSupport with a custom class or a module that is not inherited from any rails tie,
|
105
|
+
* If you want to use TurkishSupport with a custom class or a module that is not inherited from any rails tie,
|
106
|
+
you must add `using TurkishSupport` line to the class or module.
|
105
107
|
|
106
108
|
```ruby
|
107
109
|
class CustomClass
|
108
110
|
using TurkishSupport
|
109
111
|
|
110
|
-
|
112
|
+
# your code goes here
|
111
113
|
end
|
112
114
|
```
|
113
115
|
|
114
|
-
### Using Core Methods
|
115
|
-
|
116
|
-
If you want to use original set of the core methods in the same scope, you can use `Object#public_send`:
|
117
|
-
|
118
|
-
```ruby
|
119
|
-
str = 'Bağcılar'
|
120
|
-
str.public_send(:upcase) # => "BAğCıLAR"
|
121
|
-
```
|
122
|
-
|
123
116
|
## String Methods
|
124
117
|
|
125
118
|
### <=> (spaceship)
|
@@ -130,16 +123,21 @@ If you want to use original set of the core methods in the same scope, you can u
|
|
130
123
|
'c' <=> 'ca' # => -1
|
131
124
|
```
|
132
125
|
|
126
|
+
### <, <=, >, >= (comparisons)
|
127
|
+
```ruby
|
128
|
+
'd' > 'ç' # => true
|
129
|
+
'aha' >= 'ağa' # => true
|
130
|
+
'd' < 'ç' # => false
|
131
|
+
'ağa' <= 'aha' # => true
|
132
|
+
```
|
133
133
|
|
134
134
|
### [] and []=
|
135
|
-
|
136
135
|
```ruby
|
137
136
|
'Türkiye Cumhuriyeti'[/\w+/] # => "Türkiye"
|
138
137
|
'Çetin'[/[a-ğ]+/i] # => "Çe"
|
139
138
|
```
|
140
139
|
|
141
140
|
### capitalize and capitalize!
|
142
|
-
|
143
141
|
```ruby
|
144
142
|
str = 'türkÇE desteĞİ'
|
145
143
|
|
@@ -148,13 +146,11 @@ If you want to use original set of the core methods in the same scope, you can u
|
|
148
146
|
```
|
149
147
|
|
150
148
|
### casecmp
|
151
|
-
|
152
149
|
```ruby
|
153
150
|
'sıtKI'.casecmp('SITkı') # => 0
|
154
151
|
```
|
155
152
|
|
156
153
|
### downcase and downcase!
|
157
|
-
|
158
154
|
```ruby
|
159
155
|
str = 'İSMAİL'
|
160
156
|
|
@@ -163,20 +159,17 @@ If you want to use original set of the core methods in the same scope, you can u
|
|
163
159
|
```
|
164
160
|
|
165
161
|
### gsub and gsub!
|
166
|
-
|
167
162
|
```ruby
|
168
|
-
'
|
163
|
+
'ağa paşa ağa'.gsub(/\b[a-h]+\b/, 'bey') # => "bey paşa bey"
|
169
164
|
```
|
170
165
|
|
171
166
|
### index
|
172
|
-
|
173
167
|
```ruby
|
174
168
|
'?ç-!+*/-ğüı'.index(/\w+/) # => 1
|
175
169
|
'?ç-!+*/-ğüı'.index(/[a-z]+/, 2) # => 8
|
176
170
|
```
|
177
171
|
|
178
172
|
### match
|
179
|
-
|
180
173
|
```ruby
|
181
174
|
'Aşağı'.match(/\w+/)
|
182
175
|
# => #<MatchData "Aşağı">
|
@@ -195,26 +188,22 @@ If you want to use original set of the core methods in the same scope, you can u
|
|
195
188
|
```
|
196
189
|
|
197
190
|
### partition
|
198
|
-
|
199
191
|
```ruby
|
200
192
|
'Bağlarbaşı Çarşı'.partition(/\W+/) # => ["Bağlarbaşı", " ", "Çarşı"]
|
201
193
|
```
|
202
194
|
|
203
195
|
### rpartition
|
204
|
-
|
205
196
|
```ruby
|
206
197
|
'Bağlarbaşı Çarşı Kalabalık'.rpartition(/\W+/)
|
207
198
|
# => ["Bağlarbaşı Çarşı", " ", "Kalabalık"]
|
208
199
|
```
|
209
200
|
|
210
201
|
### rindex
|
211
|
-
|
212
202
|
```ruby
|
213
203
|
'şç-!+*/-ğüı'.rindex(/\w+/, 7) # => 1
|
214
204
|
```
|
215
205
|
|
216
206
|
### scan
|
217
|
-
|
218
207
|
```ruby
|
219
208
|
'Bağlarbaşı Çarşı Kalabalık'.scan(/[a-z]+/i)
|
220
209
|
# => ["Bağlarbaşı", "Çarşı", "Kalabalık"]
|
@@ -222,13 +211,11 @@ If you want to use original set of the core methods in the same scope, you can u
|
|
222
211
|
|
223
212
|
|
224
213
|
### slice and slice!
|
225
|
-
|
226
214
|
```ruby
|
227
215
|
'Duayen'.slice(/[^h-ö]+/) # => "Duaye"
|
228
216
|
```
|
229
217
|
|
230
218
|
### split
|
231
|
-
|
232
219
|
```ruby
|
233
220
|
'Bağlarbaşı Çarşı Kalabalık'.split(/\W+/)
|
234
221
|
# => ["Bağlarbaşı", "Çarşı", "Kalabalık"]
|
@@ -238,22 +225,18 @@ If you want to use original set of the core methods in the same scope, you can u
|
|
238
225
|
```
|
239
226
|
|
240
227
|
### sub and sub!
|
241
|
-
|
242
228
|
```ruby
|
243
229
|
'ağapaşaağa'.sub(/[a-h]+/, 'bey') # => "beypaşaağa"
|
244
230
|
```
|
245
231
|
|
246
232
|
### swapcase and swapcase!
|
247
|
-
|
248
233
|
```ruby
|
249
234
|
'TuğÇE'.swapcase # => "tUĞçe"
|
250
235
|
'TuğÇE'.swapcase! # => "tUĞçe"
|
251
236
|
```
|
252
237
|
|
253
238
|
### titleize and titleize!
|
254
|
-
|
255
239
|
*These methods are not core methods of ruby, but they are accepted as useful in most situations.*
|
256
|
-
|
257
240
|
```ruby
|
258
241
|
'türkÇE desteĞİ'.titleize # => "Türkçe Desteği"
|
259
242
|
'türkÇE desteĞİ'.titleize! # => "Türkçe Desteği"
|
@@ -261,11 +244,6 @@ If you want to use original set of the core methods in the same scope, you can u
|
|
261
244
|
# Parenthesis, quotes, etc. support
|
262
245
|
"rUBY roCkS... (really! 'tRUSt' ME)".titleize
|
263
246
|
# => "Ruby Rocks... (Really! 'Trust' Me)"
|
264
|
-
|
265
|
-
# If you don't want to capitalize conjuctions,
|
266
|
-
# simply pass a false value as parameter
|
267
|
-
"kerem VE aslı VeYa leyla İlE mecnun".titleize(false)
|
268
|
-
# => "Kerem ve Aslı veya Leyla ile Mecnun"
|
269
247
|
```
|
270
248
|
|
271
249
|
### upcase and upcase!
|
@@ -289,10 +267,18 @@ If you want to use original set of the core methods in the same scope, you can u
|
|
289
267
|
# => ["dört", "ılık", "iğne", "iki", "iyne", "üç"]
|
290
268
|
```
|
291
269
|
|
270
|
+
## Development
|
271
|
+
|
272
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
273
|
+
|
292
274
|
## Contributing
|
293
275
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
276
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sbagdat/turkish_support. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/sbagdat/turkish_suppport/blob/master/CODE_OF_CONDUCT.md).
|
277
|
+
|
278
|
+
## License
|
279
|
+
|
280
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
281
|
+
|
282
|
+
## Code of Conduct
|
283
|
+
|
284
|
+
Everyone interacting in the TurkishSupport project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct]
|
data/Rakefile
CHANGED
data/lib/turkish_support.rb
CHANGED
@@ -1,9 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'turkish_ranges'
|
4
|
+
require 'turkish_regexps'
|
5
|
+
|
1
6
|
require 'turkish_support/version'
|
2
7
|
require 'turkish_support/constants'
|
3
|
-
require 'turkish_support/helpers'
|
4
|
-
|
5
8
|
require 'turkish_support/string_methods'
|
6
9
|
require 'turkish_support/array_methods'
|
7
10
|
|
11
|
+
# The TurkishSupport module responsible for making some String and Array
|
12
|
+
# methods compatible with Turkish language by using Ruby language's refinements
|
13
|
+
# feature.
|
14
|
+
#
|
15
|
+
# You can check refinements at
|
16
|
+
# https://docs.ruby-lang.org/en/master/doc/syntax/refinements_rdoc.html
|
17
|
+
#
|
18
|
+
# === Refined Methods
|
19
|
+
# * String#<=>
|
20
|
+
# * String#[]
|
21
|
+
# * String#[]=
|
22
|
+
# * String#capitalize
|
23
|
+
# * String#casecmp
|
24
|
+
# * String#downcase
|
25
|
+
# * String#gsub
|
26
|
+
# * String#index
|
27
|
+
# * String#match
|
28
|
+
# * String#partition
|
29
|
+
# * String#rpartition
|
30
|
+
# * String#rindex
|
31
|
+
# * String#scan
|
32
|
+
# * String#slice
|
33
|
+
# * String#split
|
34
|
+
# * String#sub
|
35
|
+
# * String#swapcase
|
36
|
+
# * String#titleize
|
37
|
+
# * String#upcase
|
8
38
|
module TurkishSupport
|
9
39
|
end
|
@@ -1,15 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module TurkishSupport
|
4
|
+
# :nodoc:
|
2
5
|
refine Array do
|
3
6
|
def sort
|
4
|
-
if block_given?
|
5
|
-
|
6
|
-
|
7
|
-
sort_by do |item|
|
8
|
-
item.chars.map do |ch|
|
9
|
-
ALPHABET.include?(ch) ? ASCII_ALPHABET[ch] : ch.ord
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
7
|
+
return super if block_given?
|
8
|
+
|
9
|
+
sort_by { _1.chars.map { |ch| TurkishRanges::TrText.new(ch).code } }
|
13
10
|
end
|
14
11
|
|
15
12
|
def sort!
|
@@ -1,38 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module TurkishSupport
|
4
|
+
CASE_METHODS = %i[downcase
|
5
|
+
downcase!
|
6
|
+
upcase
|
7
|
+
upcase!
|
8
|
+
capitalize
|
9
|
+
capitalize!
|
10
|
+
swapcase
|
11
|
+
swapcase!].freeze
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
sub
|
30
|
-
sub!
|
31
|
-
gsub
|
32
|
-
gsub!].freeze
|
33
|
-
REGEX_METHS = REGEX_REQUIRED_METHODS + REGEX_OPTIONAL_METHODS
|
34
|
-
RANGE_REGEXP = /\[[^\]]*?([#{ALPHABET}]-[#{ALPHABET}])[^\[]*?\]/.freeze
|
35
|
-
|
36
|
-
CONJUCTION = %w[ve ile veya].freeze
|
37
|
-
SPECIAL_CHARS = %q{("'}
|
13
|
+
REGEX_METHODS = %i[[]
|
14
|
+
[]=
|
15
|
+
index
|
16
|
+
gsub
|
17
|
+
gsub!
|
18
|
+
match
|
19
|
+
rindex
|
20
|
+
partition
|
21
|
+
rpartition
|
22
|
+
scan
|
23
|
+
slice
|
24
|
+
slice!
|
25
|
+
split
|
26
|
+
sub
|
27
|
+
sub!
|
28
|
+
gsub
|
29
|
+
gsub!].freeze
|
38
30
|
end
|