turkish_ranges 0.1.1 → 0.1.2

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: 541ad676ae6e965932c387cc84ab9792636b640da5c5490ec0e456805a76c0d8
4
- data.tar.gz: '0428644d1d5f0b167ed91235013ba23b5a465c5aad7be2150fb9c553982d4a55'
3
+ metadata.gz: 386efc347ab40b587cc60ad3ca10f35fd9b5e04ceb8ad96603804d8bd3e69eca
4
+ data.tar.gz: 6dd8c9396b8b67c7782359839a6178d23acb232846b48c95d8c9cc4b3a6f8744
5
5
  SHA512:
6
- metadata.gz: 1eab65f0fc36146349dfe13dd72782f7b06e00386f83ddd8e07677b4a78b2736c9ce73bcfc85b9663fa969ca76ba4eb1e01ab0ca8be88a6ba0eb3ec7bb5fb419
7
- data.tar.gz: 504e32de91f19004c41f95898da7a22f2d9a3c8b93928cd117aa424d70a5c736249e45dd3c779cb74ad2253fae4ea46a36ffd496a8a11676a650c91b536b216c
6
+ metadata.gz: 95f5d95590fb60fb2b752dedb9a9924bc1f508f60dae4da0ed6d3eb7357bd8926900710fd501dbad46ed7d24729b4942dcf681ae28b49b9f54653eb9f8d1f723
7
+ data.tar.gz: e58b346c366cf4336fcc380220190796a5d665be7caa4db1f2124e9dc6b689d9c4a3cf85466c3f4aae9bf8d0215ef6004f2c09731da5399c0dacd11039f4d2b8
@@ -1,7 +1,17 @@
1
- ## [Version 0.0.1](https://github.com/sbagdat/turkish_ranges/releases/tag/v0.1.0) (2020-11-23)
1
+ # Changelog
2
+ ## [Version 0.1.2](https://github.com/sbagdat/turkish_ranges/releases/tag/v0.1.1) (2020-11-24)
3
+ ### Fixed
4
+ - Fix a bug related to string comparison [`e0a8754`](https://github.com/sbagdat/turkish_ranges/commit/e0a8754)
5
+ - Add an annotation to readme about current state of the project [`fbb69a4`](https://github.com/sbagdat/turkish_ranges/commit/fbb69a4)
6
+ ### Removed
7
+ - Remove method: TrText#codepoints_sum - It was responsible for calculating total codepoints of each letter in the string [`e0a8754`](https://github.com/sbagdat/turkish_ranges/commit/e0a8754)
2
8
 
3
- ### New features
9
+ ## [Version 0.1.1](https://github.com/sbagdat/turkish_ranges/releases/tag/v0.1.1) (2020-11-23)
10
+ ### Fixed
11
+ - Fix paths in project's Gemfile [`001001f`](https://github.com/sbagdat/turkish_ranges/commit/001001f)
4
12
 
13
+ ## [Version 0.1.0](https://github.com/sbagdat/turkish_ranges/releases/tag/v0.1.0) (2020-11-23)
14
+ ### Added
5
15
  - Capability to create ranges containing turkish characters [`f1f4c5b`](https://github.com/sbagdat/turkish_ranges/commit/f1f4c5b)
6
16
  - Capability to compare string containing turkish characters [`f1f4c5b`](https://github.com/sbagdat/turkish_ranges/commit/f1f4c5b)
7
17
  - Creating strings with TrText#new [`f1f4c5b`](https://github.com/sbagdat/turkish_ranges/CHANGELOG.md/commit/f1f4c5b)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- turkish_ranges (0.1.1)
4
+ turkish_ranges (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -7,6 +7,9 @@
7
7
 
8
8
  Ranges and comparisons meet Turkish language.
9
9
 
10
+ **NOTICE:** This gem can create one-dimensional ranges like `a`..`z` and multi-dimensional ranges like `aa`..`az`. It can't
11
+ create complex ranges like `a`..`abc` right now. I have intended to add this feature in the near future.
12
+
10
13
  ## Installation
11
14
 
12
15
  Add this line to your application's Gemfile:
data/Rakefile CHANGED
@@ -3,4 +3,10 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
+ task :cops do
7
+ sh 'rubocop'
8
+ puts '-' * 50
9
+ sh 'reek'
10
+ end
11
+
6
12
  task default: :spec
@@ -3,8 +3,8 @@
3
3
  require 'turkish_ranges/version'
4
4
  require 'turkish_ranges/tr_text'
5
5
 
6
- # Responsible for generating ranges include Turkish specific chars
7
- # like ş, ç, ğ, ...
6
+ # Responsible for generating ranges containing Turkish specific chars
7
+ # like ş, ç, ğ, etc and comparing strings, they're containing Turkish
8
+ # specific chars, too.
8
9
  module TurkishRanges
9
10
  end
10
-
@@ -7,9 +7,7 @@ module TurkishRanges
7
7
 
8
8
  # Sets the letters for the `TrText`.
9
9
  # @return [String] character sequence
10
- attr_reader :letters
11
-
12
- private :letters
10
+ attr_reader :letters, :letters_length
13
11
 
14
12
  # Using for character mapping
15
13
  MAP = 'DHJPTVdhiptvÈğıØşÝèĠIJøŠý'.chars.zip('ÇĞİÖŞÜçğıöşüDHJPTVdhiptv'.chars).to_h.freeze
@@ -24,14 +22,17 @@ module TurkishRanges
24
22
  # @return [TrText]
25
23
  def initialize(letters)
26
24
  @letters = letters
25
+ @letters_length = letters.length
27
26
  end
28
27
 
29
28
  # Using for object comparison
30
29
  #
31
30
  # @param [TrText] other
32
- # # @return [Integer] 1, 0 or -1
31
+ # @return [Integer] 1, 0 or -1
33
32
  def <=>(other)
34
- codepoints_sum <=> other.codepoints_sum
33
+ return 0 if letters == other.letters
34
+
35
+ compare_chars(zip_chars_with(other))
35
36
  end
36
37
 
37
38
  # Calculates codepoint of a single characacter based on ASCII_ALPHABET
@@ -41,13 +42,6 @@ module TurkishRanges
41
42
  ASCII_ALPHABET[letters] || letters&.ord.to_i
42
43
  end
43
44
 
44
- # Calculates the sum of codepoints in letters
45
- #
46
- # @return [Integer]
47
- def codepoints_sum
48
- letters.chars.map { TrText.new(_1) }.map(&:code).inject(:+)
49
- end
50
-
51
45
  # Calculates the successor string from `letters`
52
46
  #
53
47
  # @return [String]
@@ -78,7 +72,43 @@ module TurkishRanges
78
72
  def inspect
79
73
  letters
80
74
  end
75
+
76
+ protected
77
+
78
+ # Creates a zipped array from letters
79
+ #
80
+ # @param [TrText] other
81
+ # @return [Array] contains char pairs of each letters
82
+ def zip_chars_with(other)
83
+ max_length = [letters_length, other.letters_length].max
84
+ left_side = letters.ljust(max_length).chars
85
+ right_side = other.letters.ljust(max_length).chars
86
+ left_side.zip(right_side)
87
+ end
88
+
89
+ private
90
+
91
+ # Compares left and right side of spaceship operator
92
+ # If left side is bigger than right side returns 1,
93
+ # otherwise returns -1
94
+ #
95
+ # @param [Array] zipped_chars
96
+ # @return [Integer] 1 or -1
97
+ def compare_chars(zipped_chars)
98
+ zipped_chars.each do |char_pairs|
99
+ left, right = char_pairs
100
+ next if left == right
101
+
102
+ return single_char(left).code > single_char(right).code ? 1 : -1
103
+ end
104
+ end
105
+
106
+ # Creates an instance of TrText
107
+ #
108
+ # @param [String] letter
109
+ # @return [TrText]
110
+ def single_char(letter)
111
+ self.class.new(letter)
112
+ end
81
113
  end
82
114
  end
83
-
84
- (TurkishRanges::TrText.new("a")..TurkishRanges::TrText.new("z")).to_a
@@ -2,5 +2,5 @@
2
2
 
3
3
  module TurkishRanges
4
4
  # Version of TurkishRanges
5
- VERSION = '0.1.1'
5
+ VERSION = '0.1.2'
6
6
  end
@@ -19,12 +19,6 @@ RSpec.describe 'TrLetterSpec' do
19
19
  end
20
20
  end
21
21
 
22
- context '#codepoints_sum' do
23
- it 'returns total codepoints of letters' do
24
- expect(TrText.new('ABCÇ').codepoints_sum).to eq 65 + 66 + 67 + 68
25
- end
26
- end
27
-
28
22
  context 'when doing comparisons' do
29
23
  it 'can compare two letters' do
30
24
  expect(TrText.new('Ş') > TrText.new('Ğ')).to be true
@@ -60,9 +54,9 @@ RSpec.describe 'TrLetterSpec' do
60
54
  expect(upper_case_range.to_a.join).to eq g_to_u_upper_case
61
55
  end
62
56
 
63
- it 'creates ranges of mutliple characters' do
64
- z_to_ad_lower_case = 'zaaabacaçad'
65
- z_to_ad_upper_case = 'ZAAABACAÇAD'
57
+ it 'creates empty range if left side is bigger' do
58
+ z_to_ad_lower_case = ''
59
+ z_to_ad_upper_case = ''
66
60
  lower_case_range = TrText.new('z')..TrText.new('ad')
67
61
  upper_case_range = TrText.new('Z')..TrText.new('AD')
68
62
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turkish_ranges
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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-23 00:00:00.000000000 Z
11
+ date: 2020-11-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ranges and string comparisons meet Turkish language. You can use it anywhere
14
14
  in your code, Range, Regexp, etc..