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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 661daa780f4a86533a3e5b3d7607b5d131549c928ab65db35598f93fbf89c103
4
- data.tar.gz: 6006aa50c352658fbac41af13e40e77c49e09ea9887bb2ac605457f0734f14ad
3
+ metadata.gz: e52aee159fcb443687f4d18c2dd77181c0bf4633dc4cdc38a123a8d8522e8865
4
+ data.tar.gz: 6e4c1d6ee4ac28d67eaef74df372dd6fc14bf1bdde81555008a24295ce21363e
5
5
  SHA512:
6
- metadata.gz: 2b06283e2a0626719a52e3e18e26bc3c4555ecedc2f2e7b05dd998a15953ef0ddf0cbf0b00ce88364941e3c8451467f9d24b6a3ee972f52422e6133e67ff1a30
7
- data.tar.gz: e1cffa240cec788281aee54e8a1435255f90e4757b945e5768d100d48408168071a3137e1ba1597d1ce46d8383635e2c426b9fdb9371b02fde58edf38aeb5af0
6
+ metadata.gz: b597463d4655ad862c8ba64c0c9020c543b4a85ea606acefb350f8c03164caa2395a1a06b77963c660fe9fb765f15c447e94272a95b722fc6a84c916f7f77d93
7
+ data.tar.gz: 863aefb578b72b6cee9380c53b13f5ccb275263dd52a846c8afe4647c25448642dca816ce3f762809dffa9e0b9ffb3660a645c569b506025afa491fc294830c8
@@ -0,0 +1,8 @@
1
+ ---
2
+ detectors:
3
+ IrresponsibleModule:
4
+ exclude:
5
+ - TurkishSupport
6
+ UncommunicativeVariableName:
7
+ exclude:
8
+ - TurkishSupport
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
+ --require spec_helper
@@ -1,11 +1,14 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.7
3
- StringLiterals:
4
- EnforcedStyle: single_quotes
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
@@ -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
@@ -1,4 +1,5 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
2
 
3
- # Specify your gem's dependencies in turkish_support.gemspec
3
+ source 'https://rubygems.org'
4
+ ruby '~> 2.7.0'
4
5
  gemspec
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
- [![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)
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
- gem 'turkish_support'
44
+ ```
45
+ gem 'turkish_support'
46
+ ```
48
47
 
49
48
  And then execute:
50
49
 
51
- $ bundle
50
+ ```
51
+ $ bundle
52
+ ```
52
53
 
53
54
  Or install it yourself as:
54
55
 
55
- $ gem install turkish_support
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 where you want to activate it.
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 Test
79
+ class CanSpeakInTurkish
81
80
  using TurkishSupport
82
- def up_me(str)
83
- str.upcase
81
+
82
+ def split_me_up(string, sep)
83
+ string.split(sep)
84
84
  end
85
85
  end
86
86
 
87
- Test.new.up_me('içel') # => "İÇEL"
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 SampleModel < ActiveRecord::Base
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, you must add `using TurkishSupport` line to the class or module.
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
- 'ağapaşaağa'.gsub(/[a-h]+/, 'bey')
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
- 1. Fork it ( http://github.com/sbagdat/turkish_support/fork )
295
- 2. Create your feature branch (`git checkout -b my-new-feature`)
296
- 3. Commit your changes (`git commit -am 'Add some feature'`)
297
- 4. Push to the branch (`git push origin my-new-feature`)
298
- 5. Create new Pull Request
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
@@ -1,6 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
8
+ task :cops do
9
+ sh 'rubocop'
10
+ puts '-' * 50
11
+ sh 'reek'
12
+ end
13
+
6
14
  task default: :spec
@@ -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
- super
6
- else
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 TurkishSupportHelpers
4
- ALPHA = { lower: 'abcçdefgğhıijklmnoöpqrsştuüvwxyz',
5
- upper: 'ABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZ',
6
- tr_lower: 'çğıiöşü',
7
- tr_upper: 'ÇĞIİÖŞÜ' }.freeze
8
- ALPHABET = ALPHA[:upper] + ALPHA[:lower]
9
- ASCII_ALPHABET = ALPHABET.chars.map.with_index { |ch, i| [ch, i + 65] }.to_h
10
- META_CHARS = { '\w' => '[\p{Latin}\d_]', '\W' => '[^\p{Latin}\d_]' }.freeze
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
- CASE_RELATED_METHS = %i[downcase
13
- downcase!
14
- upcase
15
- upcase!
16
- capitalize
17
- capitalize!].freeze
18
-
19
- REGEX_REQUIRED_METHODS = %i[match scan].freeze
20
- REGEX_OPTIONAL_METHODS = %i[[]
21
- []=
22
- index
23
- rindex
24
- partition
25
- rpartition
26
- slice
27
- slice!
28
- split
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