turkish_support 1.0.4 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +4 -0
- data/.travis.yml +1 -1
- data/CODE_OF_CONDUCT.md +46 -0
- data/LICENSE.txt +1 -1
- data/README.md +13 -11
- data/lib/turkish_support/array_methods.rb +6 -7
- data/lib/turkish_support/constants.rb +35 -48
- data/lib/turkish_support/helpers.rb +12 -35
- data/lib/turkish_support/string_methods.rb +42 -28
- data/lib/turkish_support/version.rb +1 -1
- data/spec/array_spec.rb +103 -0
- data/spec/helpers_spec.rb +37 -134
- data/spec/string_spec.rb +415 -0
- data/spec/turkish_support_spec.rb +1 -607
- data/turkish_support.gemspec +5 -5
- metadata +25 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 661daa780f4a86533a3e5b3d7607b5d131549c928ab65db35598f93fbf89c103
|
4
|
+
data.tar.gz: 6006aa50c352658fbac41af13e40e77c49e09ea9887bb2ac605457f0734f14ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b06283e2a0626719a52e3e18e26bc3c4555ecedc2f2e7b05dd998a15953ef0ddf0cbf0b00ce88364941e3c8451467f9d24b6a3ee972f52422e6133e67ff1a30
|
7
|
+
data.tar.gz: e1cffa240cec788281aee54e8a1435255f90e4757b945e5768d100d48408168071a3137e1ba1597d1ce46d8383635e2c426b9fdb9371b02fde58edf38aeb5af0
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
## Our Standards
|
8
|
+
|
9
|
+
Examples of behavior that contributes to creating a positive environment include:
|
10
|
+
|
11
|
+
* Using welcoming and inclusive language
|
12
|
+
* Being respectful of differing viewpoints and experiences
|
13
|
+
* Gracefully accepting constructive criticism
|
14
|
+
* Focusing on what is best for the community
|
15
|
+
* Showing empathy towards other community members
|
16
|
+
|
17
|
+
Examples of unacceptable behavior by participants include:
|
18
|
+
|
19
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
20
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
21
|
+
* Public or private harassment
|
22
|
+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
23
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
24
|
+
|
25
|
+
## Our Responsibilities
|
26
|
+
|
27
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
28
|
+
|
29
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
+
|
31
|
+
## Scope
|
32
|
+
|
33
|
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
34
|
+
|
35
|
+
## Enforcement
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at sbagdat@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
38
|
+
|
39
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
40
|
+
|
41
|
+
## Attribution
|
42
|
+
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
44
|
+
|
45
|
+
[homepage]: http://contributor-covenant.org
|
46
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,16 +2,15 @@
|
|
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)
|
6
5
|
|
7
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`.
|
8
7
|
|
9
8
|
## Requirements
|
10
9
|
|
11
|
-
* Ruby >= 2.
|
12
|
-
* Rails >=
|
10
|
+
* Ruby >= 2.7.0
|
11
|
+
* Rails >= 6.0.0
|
13
12
|
|
14
|
-
__Notice:__ TurkishSupport uses
|
13
|
+
__Notice:__ TurkishSupport uses __refinements__ instead of monkey patching.
|
15
14
|
|
16
15
|
* [Installation](#installation)
|
17
16
|
* [Usage](#usage)
|
@@ -19,8 +18,8 @@ __Notice:__ TurkishSupport uses refinements instead of monkey patching. ~~Refine
|
|
19
18
|
* [Using with ruby on rails](#using-with-ruby-on-rails)
|
20
19
|
* [Using Core Methods](#using-core-methods)
|
21
20
|
* [String Methods](#string-methods)
|
21
|
+
* [#<=>](#-spaceship)
|
22
22
|
* [#[] and #[]=](#-and-)
|
23
|
-
* [#=~](#-equal-tilda)
|
24
23
|
* [capitalize](#capitalize-and-capitalize)
|
25
24
|
* [casecmp](#casecmp)
|
26
25
|
* [downcase](#downcase-and-downcase)
|
@@ -123,17 +122,20 @@ If you want to use original set of the core methods in the same scope, you can u
|
|
123
122
|
|
124
123
|
## String Methods
|
125
124
|
|
126
|
-
###
|
127
|
-
|
125
|
+
### <=> (spaceship)
|
128
126
|
```ruby
|
129
|
-
'
|
130
|
-
'
|
127
|
+
'Cahit' <=> 'Çağla' # => -1
|
128
|
+
'Sıtkı' <=> 'Ömer' # => 1
|
129
|
+
'Eren' <=> 'Eren' # => 0
|
130
|
+
'c' <=> 'ca' # => -1
|
131
131
|
```
|
132
132
|
|
133
|
-
|
133
|
+
|
134
|
+
### [] and []=
|
134
135
|
|
135
136
|
```ruby
|
136
|
-
'
|
137
|
+
'Türkiye Cumhuriyeti'[/\w+/] # => "Türkiye"
|
138
|
+
'Çetin'[/[a-ğ]+/i] # => "Çe"
|
137
139
|
```
|
138
140
|
|
139
141
|
### capitalize and capitalize!
|
@@ -1,13 +1,12 @@
|
|
1
1
|
module TurkishSupport
|
2
2
|
refine Array do
|
3
3
|
def sort
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
ch.ord
|
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
|
11
10
|
end
|
12
11
|
end
|
13
12
|
end
|
@@ -1,51 +1,38 @@
|
|
1
|
-
|
2
|
-
ALPHA = {
|
3
|
-
lower: 'abcçdefgğhıijklmnoöpqrsştuüvwxyz',
|
4
|
-
upper: 'ABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZ',
|
5
|
-
tr_lower: 'çğıiöşü',
|
6
|
-
tr_upper: 'ÇĞIİÖŞÜ'
|
7
|
-
}.freeze
|
1
|
+
# frozen_string_literal: true
|
8
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
|
9
8
|
ALPHABET = ALPHA[:upper] + ALPHA[:lower]
|
10
|
-
|
11
|
-
META_CHARS = {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
downcase!
|
40
|
-
upcase
|
41
|
-
upcase!
|
42
|
-
capitalize
|
43
|
-
capitalize!
|
44
|
-
).freeze
|
45
|
-
|
46
|
-
RANGE_REGEXP = /\[[^\]]*?([#{ALPHABET}]-[#{ALPHABET}])[^\[]*?\]/
|
47
|
-
|
48
|
-
CONJUCTIONS = %w(ve ile veya).freeze
|
49
|
-
|
50
|
-
SPECIAL_CHARS = %q{("'}.freeze
|
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
|
11
|
+
|
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{("'}
|
51
38
|
end
|
@@ -6,7 +6,7 @@ module TurkishSupportHelpers
|
|
6
6
|
|
7
7
|
while re.match(RANGE_REGEXP)
|
8
8
|
re.scan(RANGE_REGEXP).flatten.compact.each do |matching|
|
9
|
-
re.gsub! matching, translate_range(matching, pattern.casefold?)
|
9
|
+
re.gsub! matching, translate_range(matching, casefold: pattern.casefold?)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -14,38 +14,28 @@ module TurkishSupportHelpers
|
|
14
14
|
Regexp.new(re.force_encoding('UTF-8'), Regexp::FIXEDENCODING | options)
|
15
15
|
end
|
16
16
|
|
17
|
-
def translate_range(range_as_string, casefold
|
17
|
+
def translate_range(range_as_string, casefold: false)
|
18
18
|
return '' unless range_as_string
|
19
19
|
|
20
|
-
range_as_string.gsub
|
20
|
+
range_as_string = range_as_string.gsub(/\[\]/, '')
|
21
21
|
first, last = range_as_string.split('-')
|
22
|
-
|
23
22
|
expand_range(first, last, casefold)
|
24
23
|
end
|
25
24
|
|
26
|
-
def
|
27
|
-
|
28
|
-
unless valid_meths.include?(meth) && string.is_a?(String)
|
29
|
-
raise ArgumentError, 'Invalid arguments for method `prepare_for`!'
|
30
|
-
end
|
31
|
-
|
32
|
-
method("prepare_for_#{meth}").call(string)
|
25
|
+
def tr_char?(char)
|
26
|
+
tr_lower?(char) || tr_upper?(char)
|
33
27
|
end
|
34
28
|
|
35
|
-
def
|
36
|
-
tr_lower?
|
29
|
+
def tr_lower?(char)
|
30
|
+
ALPHA[:tr_lower].include? char
|
37
31
|
end
|
38
32
|
|
39
|
-
def
|
40
|
-
ALPHA[:
|
41
|
-
end
|
42
|
-
|
43
|
-
def tr_upper?(ch)
|
44
|
-
ALPHA[:tr_upper].include? ch
|
33
|
+
def tr_upper?(char)
|
34
|
+
ALPHA[:tr_upper].include? char
|
45
35
|
end
|
46
36
|
|
47
37
|
def conjuction?(string)
|
48
|
-
|
38
|
+
CONJUCTION.include? string
|
49
39
|
end
|
50
40
|
|
51
41
|
def start_with_a_special_char?(string)
|
@@ -54,21 +44,6 @@ module TurkishSupportHelpers
|
|
54
44
|
|
55
45
|
private
|
56
46
|
|
57
|
-
def prepare_for_upcase(string)
|
58
|
-
string.tr(ALPHA[:tr_lower], ALPHA[:tr_upper])
|
59
|
-
end
|
60
|
-
|
61
|
-
def prepare_for_downcase(string)
|
62
|
-
string.tr(ALPHA[:tr_upper], ALPHA[:tr_lower])
|
63
|
-
end
|
64
|
-
|
65
|
-
def prepare_for_capitalize(string)
|
66
|
-
[
|
67
|
-
prepare_for(:upcase, string.chr).upcase,
|
68
|
-
prepare_for(:downcase, self[1..-1]).downcase
|
69
|
-
].join
|
70
|
-
end
|
71
|
-
|
72
47
|
def expand_range(first, last, casefold)
|
73
48
|
if lower.include?(first) && lower.include?(last)
|
74
49
|
downcase_range(first, last, casefold)
|
@@ -91,6 +66,7 @@ module TurkishSupportHelpers
|
|
91
66
|
|
92
67
|
def lower(first = nil, last = nil)
|
93
68
|
return ALPHA[:lower] if first.nil? || last.nil?
|
69
|
+
|
94
70
|
ALPHA[:lower][ALPHA[:lower].index(first)..ALPHA[:lower].index(last)]
|
95
71
|
end
|
96
72
|
|
@@ -100,6 +76,7 @@ module TurkishSupportHelpers
|
|
100
76
|
|
101
77
|
def upper(first = nil, last = nil)
|
102
78
|
return ALPHA[:upper] if first.nil? || last.nil?
|
79
|
+
|
103
80
|
ALPHA[:upper][ALPHA[:upper].index(first)..ALPHA[:upper].index(last)]
|
104
81
|
end
|
105
82
|
|
@@ -1,50 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module TurkishSupport
|
2
|
-
refine String do
|
3
|
-
|
4
|
+
refine String do # rubocop:disable Metrics/BlockLength
|
5
|
+
REGEX_METHS.each do |meth|
|
4
6
|
define_method meth do |*args|
|
5
|
-
extend
|
6
|
-
|
7
|
-
if RE_RE_METHS.include?(meth) || args[0].is_a?(Regexp)
|
8
|
-
args[0] = translate_regexp(args[0])
|
9
|
-
end
|
7
|
+
extend TurkishSupportHelpers
|
10
8
|
|
11
|
-
|
9
|
+
args[0] = translate_regexp(args[0]) if REGEX_REQUIRED_METHODS.include?(meth) || args[0].is_a?(Regexp)
|
10
|
+
instance_exec { super(*args) }
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
15
14
|
CASE_RELATED_METHS.each do |meth|
|
16
|
-
|
17
|
-
define_method(meth) do
|
18
|
-
extend(TurkishSupportHelpers)
|
19
|
-
str = prepare_for(non_destructive, self).public_send(non_destructive)
|
20
|
-
return meth.to_s.end_with?('!') ? public_send(:replace, str) : str
|
21
|
-
end
|
15
|
+
define_method(meth) { super(:turkic) }
|
22
16
|
end
|
23
17
|
|
24
|
-
def titleize(
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
def titleize(conjuction: true)
|
19
|
+
extend TurkishSupportHelpers
|
20
|
+
|
21
|
+
downcase.split.map do |word|
|
22
|
+
if !conjuction && conjuction?(word)
|
28
23
|
word
|
29
24
|
elsif start_with_a_special_char?(word)
|
30
|
-
word.
|
25
|
+
word.chr + (word.length > 1 ? word[1..].capitalize : '')
|
31
26
|
else
|
32
27
|
word.capitalize
|
33
28
|
end
|
34
29
|
end.join(' ')
|
35
30
|
end
|
36
31
|
|
37
|
-
def titleize!(
|
38
|
-
replace(titleize(
|
32
|
+
def titleize!(conjuction: true)
|
33
|
+
replace(titleize(conjuction: conjuction))
|
39
34
|
end
|
40
35
|
|
41
36
|
def swapcase
|
42
|
-
extend
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
extend TurkishSupportHelpers
|
38
|
+
|
39
|
+
chars.map do |c|
|
40
|
+
if tr_char?(c)
|
41
|
+
tr_lower?(c) ? c.upcase : c.downcase
|
46
42
|
else
|
47
|
-
|
43
|
+
c.instance_exec { super }
|
48
44
|
end
|
49
45
|
end.join
|
50
46
|
end
|
@@ -53,8 +49,26 @@ module TurkishSupport
|
|
53
49
|
replace(swapcase)
|
54
50
|
end
|
55
51
|
|
56
|
-
def casecmp(
|
57
|
-
upcase.
|
52
|
+
def casecmp(other)
|
53
|
+
upcase.instance_exec { super(other.upcase) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def <=>(other)
|
57
|
+
return nil unless other.is_a? String
|
58
|
+
|
59
|
+
each_char.with_index do |ch, i|
|
60
|
+
position1 = ASCII_ALPHABET[ch]
|
61
|
+
position2 = ASCII_ALPHABET[other[i]]
|
62
|
+
|
63
|
+
return (position2.nil? ? 0 : -1) if position1.nil?
|
64
|
+
return 1 if position2.nil?
|
65
|
+
return (position1 < position2 ? -1 : 1) if position1 != position2
|
66
|
+
end
|
67
|
+
|
68
|
+
return 0 if length == other.length
|
69
|
+
return -1 if length < other.length
|
70
|
+
|
71
|
+
1
|
58
72
|
end
|
59
73
|
end
|
60
74
|
end
|