turkish_support 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +11 -2
- data/lib/turkish_support/array_methods.rb +1 -2
- data/lib/turkish_support/constants.rb +6 -1
- data/lib/turkish_support/helpers.rb +1 -1
- data/lib/turkish_support/string_methods.rb +19 -1
- data/lib/turkish_support/version.rb +1 -1
- data/spec/turkish_support_spec.rb +63 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bf5b94d930d37d61a0712cf5153278d446977829e4a8f6b10f95d0e237953bb3
|
4
|
+
data.tar.gz: 46bf4bd9b65029b24979315db8a5e0595665e267d9d739530ad9d77d39b2b2ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b200823ace98c49c4e2c7be185771bb9bb9390ba3b6c693786a99b2caef83bbbd399a6df4af45358087016e45c39e4097f0697c4db6aca31950bdb6990f5f70
|
7
|
+
data.tar.gz: e6d100a4395f0fc6c792aa2a105a7f9b739b34b97677e25693ab46ab152fffa2f345b9ce3ba14811b20ac27ebf8d3b1fa9b9d4246531fd9ab44d02b1455bb030
|
data/.rubocop.yml
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
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
|
|
@@ -11,7 +10,7 @@ Turkish character support for core ruby methods. This gem provides support nearl
|
|
11
10
|
* Ruby >= 2.0.0
|
12
11
|
* Rails >= 4.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,6 +18,7 @@ __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
23
|
* [#=~](#-equal-tilda)
|
24
24
|
* [capitalize](#capitalize-and-capitalize)
|
@@ -123,6 +123,15 @@ If you want to use original set of the core methods in the same scope, you can u
|
|
123
123
|
|
124
124
|
## String Methods
|
125
125
|
|
126
|
+
### <=> (spaceship)
|
127
|
+
```ruby
|
128
|
+
'Cahit' <=> 'Çağla' # => -1
|
129
|
+
'Sıtkı' <=> 'Ömer' # => 1
|
130
|
+
'Eren' <=> 'Eren' # => 0
|
131
|
+
'c' <=> 'ca' # => -1
|
132
|
+
```
|
133
|
+
|
134
|
+
|
126
135
|
### [] and []=
|
127
136
|
|
128
137
|
```ruby
|
@@ -7,7 +7,12 @@ module TurkishSupportHelpers
|
|
7
7
|
}.freeze
|
8
8
|
|
9
9
|
ALPHABET = ALPHA[:upper] + ALPHA[:lower]
|
10
|
-
|
10
|
+
|
11
|
+
ASCII_ALPHABET = ALPHABET.chars.map.with_index do |ch, i|
|
12
|
+
# Add 65 to put special chars and numbers in correct order
|
13
|
+
[ch, i + 65]
|
14
|
+
end.to_h
|
15
|
+
|
11
16
|
META_CHARS = {
|
12
17
|
'\w' => '[\p{Latin}\d_]',
|
13
18
|
'\W' => '[^\p{Latin}\d_]'
|
@@ -24,7 +24,7 @@ module TurkishSupportHelpers
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def prepare_for(meth, string)
|
27
|
-
valid_meths = %i
|
27
|
+
valid_meths = %i[upcase downcase capitalize]
|
28
28
|
unless valid_meths.include?(meth) && string.is_a?(String)
|
29
29
|
raise ArgumentError, 'Invalid arguments for method `prepare_for`!'
|
30
30
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module TurkishSupport
|
2
|
-
refine String do
|
2
|
+
refine String do # rubocop:disable Metrics/BlockLength
|
3
3
|
(RE_RE_METHS + RE_OP_METHS).each do |meth|
|
4
4
|
define_method meth do |*args|
|
5
5
|
extend(TurkishSupportHelpers)
|
@@ -56,5 +56,23 @@ module TurkishSupport
|
|
56
56
|
def casecmp(other_string)
|
57
57
|
upcase.public_send(:casecmp, other_string.upcase)
|
58
58
|
end
|
59
|
+
|
60
|
+
def <=>(other_string)
|
61
|
+
return nil unless other_string.is_a? String
|
62
|
+
|
63
|
+
each_char.with_index do |ch, i|
|
64
|
+
position1 = ASCII_ALPHABET[ch]
|
65
|
+
position2 = ASCII_ALPHABET[other_string[i]]
|
66
|
+
|
67
|
+
return (position2.nil? ? 0 : -1) if position1.nil?
|
68
|
+
return 1 if position2.nil?
|
69
|
+
return (position1 < position2 ? -1 : 1) if position1 != position2
|
70
|
+
end
|
71
|
+
|
72
|
+
return 0 if length == other_string.length
|
73
|
+
return -1 if length < other_string.length
|
74
|
+
return 1
|
75
|
+
|
76
|
+
end
|
59
77
|
end
|
60
78
|
end
|
@@ -15,7 +15,7 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
15
15
|
let(:upcased_english_alphabet) { [*'A'..'Z'].join }
|
16
16
|
|
17
17
|
let(:turkish_words) do
|
18
|
-
%w
|
18
|
+
%w[çamur ıhlamur insan ördek şahika ümraniye]
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '#[]' do
|
@@ -279,7 +279,7 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
279
279
|
capitalized_words = turkish_words.map { |w| w.capitalize }
|
280
280
|
|
281
281
|
expect(capitalized_words)
|
282
|
-
.to eq(%w
|
282
|
+
.to eq(%w[Çamur Ihlamur İnsan Ördek Şahika Ümraniye])
|
283
283
|
end
|
284
284
|
|
285
285
|
it 'capitalizes the first character of a string and downcase others' do
|
@@ -554,19 +554,66 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
554
554
|
end
|
555
555
|
end
|
556
556
|
end
|
557
|
+
|
558
|
+
describe "#<=>" do
|
559
|
+
let(:sorted_equal_length_strings) { %w[Cahit Çağla Ömer Sıtkı Şakir] }
|
560
|
+
let(:sorted_different_length_strings) { %w[c ca falan om saki sıt] }
|
561
|
+
context "with equal length strings" do
|
562
|
+
it "works for smaller test" do
|
563
|
+
0.upto(sorted_equal_length_strings.length - 2) do |i|
|
564
|
+
expect(sorted_equal_length_strings[i] <=> sorted_equal_length_strings[i+1]).to eq(-1)
|
565
|
+
end
|
566
|
+
end
|
567
|
+
|
568
|
+
it "works for bigger test" do
|
569
|
+
(sorted_equal_length_strings.length-1).downto(1) do |i|
|
570
|
+
expect(sorted_equal_length_strings[i] <=> sorted_equal_length_strings[i-1]).to eq(1)
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
it "works for equals test" do
|
575
|
+
sorted_equal_length_strings.each do |str|
|
576
|
+
expect(str <=> str).to eq(0)
|
577
|
+
end
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
context "with different length strings" do
|
582
|
+
it "works for smaller test" do
|
583
|
+
0.upto(sorted_different_length_strings.length - 2) do |i|
|
584
|
+
expect(sorted_different_length_strings[i] <=> sorted_different_length_strings[i+1]).to eq(-1)
|
585
|
+
end
|
586
|
+
end
|
587
|
+
|
588
|
+
it "works for bigger test" do
|
589
|
+
(sorted_different_length_strings.length-1).downto(1) do |i|
|
590
|
+
expect(sorted_different_length_strings[i] <=> sorted_different_length_strings[i-1]).to eq(1)
|
591
|
+
end
|
592
|
+
end
|
593
|
+
end
|
594
|
+
|
595
|
+
context "invalid comparisons" do
|
596
|
+
it "returns nil" do
|
597
|
+
expect("a" <=> 3.5).to eq(nil)
|
598
|
+
expect("a" <=> true).to eq(nil)
|
599
|
+
expect("a" <=> Object.new).to eq(nil)
|
600
|
+
expect("a" <=> 1).to eq(nil)
|
601
|
+
end
|
602
|
+
end
|
603
|
+
end
|
557
604
|
end
|
558
605
|
|
559
606
|
describe Array do
|
560
607
|
let(:unsorted_array1) do
|
561
|
-
%w
|
608
|
+
%w[bağcılar bahçelievler şimdi çüNKÜ olmalı üç\ kere düş ılık duy]
|
562
609
|
end
|
563
610
|
|
564
611
|
let(:sorted_array1) do
|
565
|
-
%w
|
612
|
+
%w[bağcılar bahçelievler çüNKÜ duy düş ılık olmalı şimdi üç\ kere]
|
566
613
|
end
|
567
614
|
|
568
|
-
let(:unsorted_array2) { %w
|
569
|
-
let(:sorted_array2) { %w
|
615
|
+
let(:unsorted_array2) { %w[iki Üç dört ılık İğne iyne Ul] }
|
616
|
+
let(:sorted_array2) { %w[İğne Ul Üç dört ılık iki iyne] }
|
570
617
|
|
571
618
|
let(:unsorted_array3) do
|
572
619
|
['Sıtkı1 Bağdat', 'Sıtkı Bağdat', 'a', '3s', '2 b', 'ab ']
|
@@ -578,6 +625,12 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
578
625
|
|
579
626
|
describe '#sort' do
|
580
627
|
context 'with non-destructive version' do
|
628
|
+
let(:unsorted_array_for_block_using) {
|
629
|
+
%w[ağa aça aşa aöa aüa aua afa aba]
|
630
|
+
}
|
631
|
+
let(:sorted_array_for_block_using) {
|
632
|
+
%w[aba aça afa ağa aöa aşa aua aüa]
|
633
|
+
}
|
581
634
|
it 'does not change the original value of the array' do
|
582
635
|
expect { unsorted_array1.sort }.to_not change { unsorted_array1 }
|
583
636
|
end
|
@@ -593,6 +646,10 @@ module TurkishSupport # rubocop:disable Metrics/ModuleLength
|
|
593
646
|
it 'sorts an array that include special chars, numbers, etc.' do
|
594
647
|
expect(unsorted_array3.sort).to eq(sorted_array3)
|
595
648
|
end
|
649
|
+
|
650
|
+
it 'sorts array for random conditions' do
|
651
|
+
expect(unsorted_array_for_block_using.sort {|a, b| a[1] <=> b[1]}).to eq(sorted_array_for_block_using)
|
652
|
+
end
|
596
653
|
end
|
597
654
|
|
598
655
|
context 'with destructive version' do
|
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: 1.0
|
4
|
+
version: 1.1.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: 2017-
|
11
|
+
date: 2017-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
102
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
103
|
+
rubygems_version: 2.7.3
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: Turkish character support for core ruby methods.
|