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.
@@ -1,4 +1,5 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
2
3
  using TurkishSupport
3
4
 
4
5
  module TurkishSupport
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'turkish_support/version'
@@ -18,8 +20,13 @@ Gem::Specification.new do |spec|
18
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
21
  spec.require_paths = ['lib']
20
22
 
21
- spec.required_ruby_version = '>= 2.7.0'
22
- spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.2'
23
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
24
+ spec.add_runtime_dependency 'turkish_ranges', '~> 0.1'
25
+ spec.add_runtime_dependency 'turkish_regexps', '~> 0.1'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 2.1'
23
28
  spec.add_development_dependency 'rake', '~> 13.0'
24
29
  spec.add_development_dependency 'rspec', '~> 3.10'
30
+ spec.add_development_dependency 'turkish_ranges', '~> 0.1'
31
+ spec.add_development_dependency 'turkish_regexps', '~> 0.1'
25
32
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turkish_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.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: 2020-11-06 00:00:00.000000000 Z
11
+ date: 2020-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: turkish_ranges
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: turkish_regexps
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -17,9 +45,6 @@ dependencies:
17
45
  - - "~>"
18
46
  - !ruby/object:Gem::Version
19
47
  version: '2.1'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 2.1.2
23
48
  type: :development
24
49
  prerelease: false
25
50
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +52,6 @@ dependencies:
27
52
  - - "~>"
28
53
  - !ruby/object:Gem::Version
29
54
  version: '2.1'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 2.1.2
33
55
  - !ruby/object:Gem::Dependency
34
56
  name: rake
35
57
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +80,34 @@ dependencies:
58
80
  - - "~>"
59
81
  - !ruby/object:Gem::Version
60
82
  version: '3.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: turkish_ranges
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: turkish_regexps
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.1'
61
111
  description: |-
62
112
  Turkish character support for core ruby methods
63
113
  like String#upcase, String#gsub, String#match, Array#sort, and etc...)
@@ -69,9 +119,11 @@ extra_rdoc_files: []
69
119
  files:
70
120
  - ".gitignore"
71
121
  - ".hound.yml"
122
+ - ".reek.yml"
72
123
  - ".rspec"
73
124
  - ".rubocop.yml"
74
125
  - ".travis.yml"
126
+ - CHANGELOG.md
75
127
  - CODE_OF_CONDUCT.md
76
128
  - Gemfile
77
129
  - LICENSE.txt
@@ -80,11 +132,9 @@ files:
80
132
  - lib/turkish_support.rb
81
133
  - lib/turkish_support/array_methods.rb
82
134
  - lib/turkish_support/constants.rb
83
- - lib/turkish_support/helpers.rb
84
135
  - lib/turkish_support/string_methods.rb
85
136
  - lib/turkish_support/version.rb
86
137
  - spec/array_spec.rb
87
- - spec/helpers_spec.rb
88
138
  - spec/spec_helper.rb
89
139
  - spec/string_spec.rb
90
140
  - spec/turkish_support_spec.rb
@@ -114,7 +164,6 @@ specification_version: 4
114
164
  summary: Turkish character support for core ruby methods.
115
165
  test_files:
116
166
  - spec/array_spec.rb
117
- - spec/helpers_spec.rb
118
167
  - spec/spec_helper.rb
119
168
  - spec/string_spec.rb
120
169
  - spec/turkish_support_spec.rb
@@ -1,90 +0,0 @@
1
- module TurkishSupportHelpers
2
- def translate_regexp(pattern) # rubocop:disable Metrics/AbcSize
3
- Regexp.new(pattern) unless pattern.is_a? Regexp
4
- re = pattern.source
5
- options = pattern.options
6
-
7
- while re.match(RANGE_REGEXP)
8
- re.scan(RANGE_REGEXP).flatten.compact.each do |matching|
9
- re.gsub! matching, translate_range(matching, casefold: pattern.casefold?)
10
- end
11
- end
12
-
13
- META_CHARS.each { |k, v| re.gsub!(k, v) }
14
- Regexp.new(re.force_encoding('UTF-8'), Regexp::FIXEDENCODING | options)
15
- end
16
-
17
- def translate_range(range_as_string, casefold: false)
18
- return '' unless range_as_string
19
-
20
- range_as_string = range_as_string.gsub(/\[\]/, '')
21
- first, last = range_as_string.split('-')
22
- expand_range(first, last, casefold)
23
- end
24
-
25
- def tr_char?(char)
26
- tr_lower?(char) || tr_upper?(char)
27
- end
28
-
29
- def tr_lower?(char)
30
- ALPHA[:tr_lower].include? char
31
- end
32
-
33
- def tr_upper?(char)
34
- ALPHA[:tr_upper].include? char
35
- end
36
-
37
- def conjuction?(string)
38
- CONJUCTION.include? string
39
- end
40
-
41
- def start_with_a_special_char?(string)
42
- string =~ /^[#{SPECIAL_CHARS}]/
43
- end
44
-
45
- private
46
-
47
- def expand_range(first, last, casefold)
48
- if lower.include?(first) && lower.include?(last)
49
- downcase_range(first, last, casefold)
50
- elsif upper.include?(first) && upper.include?(last)
51
- upcase_range(first, last, casefold)
52
- else
53
- raise ArgumentError, 'Invalid regexp range arguments!'
54
- end
55
- end
56
-
57
- def downcase_range(first, last, casefold)
58
- lower(first, last) +
59
- (lower_opposite(first, last) if casefold).to_s
60
- end
61
-
62
- def upcase_range(first, last, casefold)
63
- upper(first, last) +
64
- (upper_opposite(first, last) if casefold).to_s
65
- end
66
-
67
- def lower(first = nil, last = nil)
68
- return ALPHA[:lower] if first.nil? || last.nil?
69
-
70
- ALPHA[:lower][ALPHA[:lower].index(first)..ALPHA[:lower].index(last)]
71
- end
72
-
73
- def lower_opposite(first, last)
74
- upper[lower.index(first)..lower.index(last)].delete("^#{ALPHA[:tr_upper]}")
75
- end
76
-
77
- def upper(first = nil, last = nil)
78
- return ALPHA[:upper] if first.nil? || last.nil?
79
-
80
- ALPHA[:upper][ALPHA[:upper].index(first)..ALPHA[:upper].index(last)]
81
- end
82
-
83
- def upper_opposite(first, last)
84
- lower[upper.index(first)..upper.index(last)].delete("^#{ALPHA[:tr_lower]}")
85
- end
86
- end
87
-
88
- module TurkishSupport
89
- include TurkishSupportHelpers
90
- end
@@ -1,165 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'turkish_support/helpers'
5
-
6
- RSpec.configure do |config|
7
- config.include TurkishSupportHelpers
8
- using TurkishSupport
9
- end
10
-
11
- describe 'TurkishSupportHelpers' do
12
- let(:downcased_alphabet) { 'abcçdefgğhıijklmnoöpqrsştuüvwxyz' }
13
- let(:upcased_alphabet) { 'ABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZ' }
14
- let(:alphabet) { downcased_alphabet + upcased_alphabet }
15
- let(:tr_specific_lower) { 'çğıiöşü' }
16
- let(:tr_specific_upper) { 'ÇĞIİÖŞÜ' }
17
- let(:tr_all) { tr_specific_upper + tr_specific_lower }
18
- let(:conjuctions) { %w[ve ile veya] }
19
- let(:turkish_words) { %w[çamur ıhlamur insan ördek şahika ümraniye] }
20
- let(:special_chars) { %w[( " '] }
21
-
22
- describe '#tr_lower?' do
23
- it 'returns true for any Turkish specific lower case character' do
24
- expect(tr_specific_lower.chars.all? { |ch| tr_lower?(ch) }).to(eq(true))
25
- end
26
-
27
- context 'returns false' do
28
- it 'for non-Turkish specific lower case characters' do
29
- expect(downcased_alphabet.delete(tr_specific_lower).chars.any? { |ch| tr_lower?(ch) }).to(eq(false))
30
- end
31
-
32
- it 'for any upper case characters' do
33
- expect(upcased_alphabet.chars.any? { |ch| tr_lower?(ch) }).to(eq(false))
34
- end
35
-
36
- it 'for non-letter characters' do
37
- expect("\"é1!2'3^+4.,-_".chars.any? { |ch| tr_lower?(ch) }).to(eq(false))
38
- end
39
- end
40
- end
41
-
42
- describe '#tr_upper?' do
43
- it 'returns true for any Turkish specific upper case character' do
44
- expect(tr_specific_upper.chars.all? { |ch| tr_upper?(ch) }).to(eq(true))
45
- end
46
-
47
- context 'returns false' do
48
- it 'for non-Turkish specific upper case characters' do
49
- expect(upcased_alphabet.delete(tr_specific_upper).chars.any? { |ch| tr_upper?(ch) }).to(eq(false))
50
- end
51
-
52
- it 'for any lower case characters' do
53
- expect(downcased_alphabet.chars.any? { |ch| tr_upper?(ch) }).to(eq(false))
54
- end
55
-
56
- it 'for non-letter characters' do
57
- expect("\"é1!2'3^+4.,-_".chars.any? { |ch| tr_upper?(ch) }).to(eq(false))
58
- end
59
- end
60
- end
61
-
62
- describe '#tr_char?' do
63
- it 'returns true for any Turkish specific character' do
64
- expect(tr_all.chars.all? { |ch| tr_char?(ch) }).to(eq(true))
65
- end
66
-
67
- context 'returns false' do
68
- it 'for non-Turkish specific characters' do
69
- expect(alphabet.delete(tr_all).chars.any? { |ch| tr_char?(ch) }).to(eq(false))
70
- end
71
-
72
- it 'for non-letter characters' do
73
- expect("\"é1!2'3^+4.,-_".chars.any? { |ch| tr_char?(ch) }).to(eq(false))
74
- end
75
- end
76
- end
77
-
78
- describe '#conjuction?' do
79
- it 'returns true for any conjuction' do
80
- expect(conjuctions.all? { |c| conjuction?(c) }).to(eq(true))
81
- end
82
-
83
- it 'returns false for any word contains conjuction' do
84
- expect(%w[veda aile veyahut].any? { |c| conjuction?(c) }).to(eq(false))
85
- end
86
- end
87
-
88
- describe '#start_with_a_special_char?' do
89
- it 'returns true for all words starts with a special char' do
90
- special_words = turkish_words.map { |w| special_chars.sample + w }
91
- expect(special_words.all? { |word| start_with_a_special_char?(word) }).to(eq(true))
92
- end
93
-
94
- it 'returns false any words not starts with a special char' do
95
- expect(turkish_words.any? { |word| start_with_a_special_char?(word) }).to(eq(false))
96
- end
97
- end
98
-
99
- describe '#translate_range' do
100
- it 'translates a complete lower-case range correctly' do
101
- expect(translate_range('a-z')).to(eq(downcased_alphabet))
102
- end
103
-
104
- it 'translates a complete upper-case range correctly' do
105
- expect(translate_range('A-Z')).to eq(upcased_alphabet)
106
- end
107
-
108
- it 'raises an error if any arguments not a letter' do
109
- invalid_arguments = %w(1-Z A-9 1-9 a-])
110
- expect(invalid_arguments
111
- .all? do |arg|
112
- expect { translate_range(arg) }
113
- .to raise_error ArgumentError,
114
- 'Invalid regexp range arguments!'
115
- end).to eq(true)
116
- end
117
-
118
- it 'raises an error if arguments are not in same case' do
119
- expect { translate_range('a-Z') }
120
- .to(raise_error(ArgumentError, 'Invalid regexp range arguments!'))
121
- end
122
-
123
- it 'translates a partial range correctly' do
124
- expect(translate_range('d-t')).to(eq('defgğhıijklmnoöpqrsşt'))
125
- expect(translate_range('Ç-Ü')).to(eq('ÇDEFGĞHIİJKLMNOÖPQRSŞTUÜ'))
126
- end
127
-
128
- it 'translates a range correctly when casefold option is true' do
129
- expect(translate_range('d-t', casefold: true)).to(eq('defgğhıijklmnoöpqrsştĞIİÖŞ'))
130
- expect(translate_range('C-U', casefold: true)).to(eq('CÇDEFGĞHIİJKLMNOÖPQRSŞTUçğıiöş'))
131
- end
132
-
133
- it 'translates ranges created using Turkish characters' do
134
- expect(translate_range('Ç-Ü', casefold: true)).to(eq('ÇDEFGĞHIİJKLMNOÖPQRSŞTUÜçğıiöşü'))
135
- expect(translate_range('ç-ü', casefold: true)).to(eq('çdefgğhıijklmnoöpqrsştuüÇĞIİÖŞÜ'))
136
- end
137
- end
138
-
139
- describe '#translate_regexp' do
140
- it 'translates simple regexp to include Turkish characters' do
141
- expect(translate_regexp(/\w+\s[a-h]/)).to(eq(/[\p{Latin}\d_]+\s[abcçdefgğh]/))
142
- end
143
-
144
- it 'translates simple regexp range created with Turkish characters' do
145
- expect(translate_regexp(/[ç-ş]/)).to(eq(/[çdefgğhıijklmnoöpqrsş]/))
146
- end
147
-
148
- it 'preserves flags' do
149
- expect(translate_regexp(/\w+/mixu)).to(eq(/[\p{Latin}\d_]+/mixu))
150
- end
151
-
152
- it 'translates many range inside a character class' do
153
- expect(translate_regexp(/[a-ht-üy-z]/)).to(eq(/[abcçdefgğhtuüyz]/))
154
- end
155
-
156
- it 'translates many range inside different character class' do
157
- expect(translate_regexp(/[a-ht-üy-z]\s[a-dr-z]/)).to(eq(/[abcçdefgğhtuüyz]\s[abcçdrsştuüvwxyz]/))
158
- end
159
-
160
- it 'does not translate ranges outside character class' do
161
- expect(translate_regexp(/[a-h]+\se-h[ç-ş]afse-h+/))
162
- .to eq(/[abcçdefgğh]+\se-h[çdefgğhıijklmnoöpqrsş]afse-h+/)
163
- end
164
- end
165
- end