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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +5 -5
- data/lib/roqua/core_ext/enumerable/sort_by_alphanum.rb +34 -18
- data/lib/roqua-support/version.rb +1 -1
- data/spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb +10 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 774c4b5c612eff02c808d6dac48cc599664c641deb96b97c923a6d293875a5b4
|
4
|
+
data.tar.gz: 0b2dd8489e5ec1a6216db145f511d7313776efe7ea07db0604f4bb4c7bfeb3e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d69bb02afb3adb3bdf1dd64a526466d7b24f8f8b068829a8ce9dfafa2930d29de30cff451fec7ff2d91c933e390c27b2addb336124dd257856c3dc6c510d3b56
|
7
|
+
data.tar.gz: 316fedffd3ede41f162fb6b294b409b446b204e89412d29dd7f6cc7d07af300e6b3eb5abc8471cea6970944aae74b443adfcef4a3a25843d3b82d40ca39d24e9
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -10,7 +10,7 @@ GIT
|
|
10
10
|
PATH
|
11
11
|
remote: .
|
12
12
|
specs:
|
13
|
-
roqua-support (0.4.
|
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
|
37
|
-
activemodel (>= 5, <
|
38
|
-
activesupport (>= 5, <
|
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.
|
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
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
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
|
-
|
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
|
@@ -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.
|
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:
|
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.
|
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:
|