roqua-support 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0104ee377feaa85014f2a233e86c618a08de92e7b55cd273fe7832f491f070b4
4
- data.tar.gz: 7c04430ab277f7c69cb0d1cf8d54a0901cb127460b2b68e3b91ad3c01b171204
3
+ metadata.gz: 774c4b5c612eff02c808d6dac48cc599664c641deb96b97c923a6d293875a5b4
4
+ data.tar.gz: 0b2dd8489e5ec1a6216db145f511d7313776efe7ea07db0604f4bb4c7bfeb3e1
5
5
  SHA512:
6
- metadata.gz: da8540ad9f35f3738485ec3f58b28ba14c2a330ae6ae2cd4d1bfefbe46206f0c7c8b842053829dcf4e668d57c03890137f2536c559d805d51ba1c04755daf58c
7
- data.tar.gz: 01a31a8402b496e30298ceda86e2ebcbf06eb09d7453e9a56a681f159335eab03d3436487e4bb138afbe027990a1c4747acf0c3d06756a4d3ae56749144635da
6
+ metadata.gz: d69bb02afb3adb3bdf1dd64a526466d7b24f8f8b068829a8ce9dfafa2930d29de30cff451fec7ff2d91c933e390c27b2addb336124dd257856c3dc6c510d3b56
7
+ data.tar.gz: 316fedffd3ede41f162fb6b294b409b446b204e89412d29dd7f6cc7d07af300e6b3eb5abc8471cea6970944aae74b443adfcef4a3a25843d3b82d40ca39d24e9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.4.2
2
+
3
+ * Make sort_by_alphanum stable for chunks that parse to the same int like 04 and 4.
4
+
1
5
  ## 0.4.1
2
6
 
3
7
  * Add timezone to logging timestamps. Use milliseconds instead of microseconds precision.
data/Gemfile.lock CHANGED
@@ -10,7 +10,7 @@ GIT
10
10
  PATH
11
11
  remote: .
12
12
  specs:
13
- roqua-support (0.4.1)
13
+ roqua-support (0.4.2)
14
14
  active_interaction (>= 3.0, < 5.0)
15
15
  activesupport (>= 5.2, < 6.2)
16
16
  appsignal (>= 2.9, < 3.1)
@@ -33,9 +33,9 @@ GEM
33
33
  erubi (~> 1.4)
34
34
  rails-dom-testing (~> 2.0)
35
35
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
36
- active_interaction (4.0.5)
37
- activemodel (>= 5, < 7)
38
- activesupport (>= 5, < 7)
36
+ active_interaction (4.1.0)
37
+ activemodel (>= 5, < 8)
38
+ activesupport (>= 5, < 8)
39
39
  activemodel (6.0.2.2)
40
40
  activesupport (= 6.0.2.2)
41
41
  activerecord (6.0.2.2)
@@ -51,7 +51,7 @@ GEM
51
51
  bundler
52
52
  rake
53
53
  thor (>= 0.14.0)
54
- appsignal (3.0.13)
54
+ appsignal (3.0.19)
55
55
  rack
56
56
  ast (2.4.2)
57
57
  builder (3.2.4)
@@ -21,29 +21,45 @@ module Enumerable
21
21
 
22
22
  private
23
23
 
24
- def grouped_compare(a, b)
25
- loop {
26
- a_chunk, a = extract_alpha_or_number_group(a)
27
- b_chunk, b = extract_alpha_or_number_group(b)
24
+ ALL_NUM = /\d+/
25
+ ALL_ALPHA = /[A-Za-z]+/
26
+ NON_ALPHANUM = /[^A-Za-z0-9]+/
28
27
 
29
- ret = if a_chunk =~ /\d/ and b_chunk =~ /\d/
28
+ def grouped_compare(a, b)
29
+ a_scanner = StringScanner.new(a)
30
+ b_scanner = StringScanner.new(b)
31
+ # each loop has to do exactly 1 non-nil-scan on both scanners or return a non-zero value.
32
+ loop do
33
+ ret = \
34
+ if a_scanner.eos?
35
+ -1
36
+ elsif (a_chunk = a_scanner.scan(ALL_NUM))
37
+ if (b_chunk = b_scanner.scan(ALL_NUM))
38
+ if a_chunk.to_i != b_chunk.to_i
30
39
  a_chunk.to_i <=> b_chunk.to_i
31
- else
40
+ else # 03 vs 3
32
41
  a_chunk <=> b_chunk
33
42
  end
34
-
35
- return -1 if a_chunk == ''
43
+ elsif b_scanner.scan(ALL_ALPHA)
44
+ -1
45
+ else # NON_ALPHANUM
46
+ 1
47
+ end
48
+ elsif (a_chunk = a_scanner.scan(ALL_ALPHA))
49
+ if (b_chunk = b_scanner.scan(ALL_ALPHA))
50
+ a_chunk <=> b_chunk
51
+ else # ALL_NUM or NON_ALPHANUM
52
+ 1
53
+ end
54
+ else # NON_ALPHANUM
55
+ a_chunk = a_scanner.scan(NON_ALPHANUM)
56
+ if (b_chunk = b_scanner.scan(NON_ALPHANUM))
57
+ a_chunk <=> b_chunk
58
+ else
59
+ -1
60
+ end
61
+ end
36
62
  return ret if ret != 0
37
- }
38
- end
39
-
40
- def extract_alpha_or_number_group(item)
41
- matchdata = /([A-Za-z]+|[\d]+)/.match(item)
42
-
43
- if matchdata.nil?
44
- ["", ""]
45
- else
46
- [matchdata[0], item = item[matchdata.offset(0)[1] .. -1]]
47
63
  end
48
64
  end
49
65
  end
@@ -1,5 +1,5 @@
1
1
  module Roqua
2
2
  module Support
3
- VERSION = '0.4.1'.freeze
3
+ VERSION = '0.4.2'.freeze
4
4
  end
5
5
  end
@@ -11,8 +11,18 @@ describe Enumerable do
11
11
  expect(input.sort_by_alphanum(&:reverse)).to eq ["004some10thing", "004some11thing", "3another"]
12
12
  end
13
13
 
14
+ it 'treats non-alphanum as lower than alpha and num' do
15
+ input = %w[b3a b{c bԘb] # curlies are above alpha in utf-8, Ԙ is multi-byte
16
+ expect(input.sort_by_alphanum).to eq %w[b{c bԘb b3a]
17
+ end
18
+
14
19
  it 'compares number chunks as integers' do
15
20
  expect(%w(004 3).sort_by_alphanum).to eq %w(3 004)
16
21
  end
22
+
23
+ it 'sorts identical integers by asci' do
24
+ input = %w[b4e b0004e b04e b004e]
25
+ expect(input.sort_by_alphanum).to eq %w[b0004e b004e b04e b4e]
26
+ end
17
27
  end
18
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roqua-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-20 00:00:00.000000000 Z
11
+ date: 2022-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_interaction
@@ -266,7 +266,7 @@ homepage: https://github.com/roqua/roqua-support
266
266
  licenses:
267
267
  - MIT
268
268
  metadata: {}
269
- post_install_message:
269
+ post_install_message:
270
270
  rdoc_options: []
271
271
  require_paths:
272
272
  - lib
@@ -281,8 +281,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
281
281
  - !ruby/object:Gem::Version
282
282
  version: '0'
283
283
  requirements: []
284
- rubygems_version: 3.1.4
285
- signing_key:
284
+ rubygems_version: 3.1.6
285
+ signing_key:
286
286
  specification_version: 4
287
287
  summary: Helper objects and proxies used by a lot of RoQua applications
288
288
  test_files: