natural_sort_jp 0.4.1 → 0.4.3
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/Gemfile.lock +3 -1
- data/README.md +37 -0
- data/Rakefile +4 -1
- data/lib/natural_sort_jp/version.rb +1 -1
- data/lib/natural_sort_jp.rb +7 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f3f8838d4ac297fef67c7f6df14821bd9c8faba6d3c7fd883a5d0d757f16402
|
4
|
+
data.tar.gz: c97706c5e50d04416611bcd59da78111558c5b02cf054de6efb930ef691361b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28a0f4a70663395125b89aaa220f7ca70bf3e61be03a7d8207a49fb86741904d4bef70e691022329d154690fbe966651a1af2f2859089baac516743f4034b56b
|
7
|
+
data.tar.gz: 77b14aadccb905a3c986dc7534870c2c171b805d6675b7324b020bc90ec9c81ae152cdd928e80f3f07d9381fde4632ff8eb0242cbc00e0b535c560ae1a96ef84
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
natural_sort_jp (0.3
|
4
|
+
natural_sort_jp (0.4.3)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -45,7 +45,9 @@ GEM
|
|
45
45
|
unicode-display_width (2.4.2)
|
46
46
|
|
47
47
|
PLATFORMS
|
48
|
+
ruby
|
48
49
|
x86_64-darwin-21
|
50
|
+
x86_64-linux
|
49
51
|
|
50
52
|
DEPENDENCIES
|
51
53
|
bundler (~> 2.4.6)
|
data/README.md
CHANGED
@@ -36,6 +36,43 @@ NaturalSortJp.sort(
|
|
36
36
|
)
|
37
37
|
# => ["2022/1/1", "2022/01/02", "2022/01/03", "2022/1/10", "2023/1/1"]
|
38
38
|
|
39
|
+
|
40
|
+
# It can also be used in hashes, structures, and active record data structures.
|
41
|
+
|
42
|
+
NaturalSortJp.sort(
|
43
|
+
[
|
44
|
+
{ id: 1, date: '2022/1/1'},
|
45
|
+
{ id: 2, date: '2022/01/10'},
|
46
|
+
{ id: 3, date: '2022/01/03'},
|
47
|
+
{ id: 4, date: '2022/1/2'},
|
48
|
+
{ id: 5, date: '2023/1/1'}
|
49
|
+
], by: :date)
|
50
|
+
# => [
|
51
|
+
# {:id=>1, :date=>"2022/1/1"},
|
52
|
+
# {:id=>4, :date=>"2022/1/2"},
|
53
|
+
# {:id=>3, :date=>"2022/01/03"},
|
54
|
+
# {:id=>2, :date=>"2022/01/10"},
|
55
|
+
# {:id=>5, :date=>"2023/1/1"}
|
56
|
+
# ]
|
57
|
+
|
58
|
+
# and can use asc or desc option.
|
59
|
+
|
60
|
+
NaturalSortJp.sort(
|
61
|
+
[
|
62
|
+
{ id: 1, date: '2022/1/1'},
|
63
|
+
{ id: 2, date: '2022/01/10'},
|
64
|
+
{ id: 3, date: '2022/01/03'},
|
65
|
+
{ id: 4, date: '2022/1/2'},
|
66
|
+
{ id: 5, date: '2023/1/1'}
|
67
|
+
], by: :date, desc: true)
|
68
|
+
# => [
|
69
|
+
# {:id=>5, :date=>"2023/1/1"},
|
70
|
+
# {:id=>2, :date=>"2022/01/10"},
|
71
|
+
# {:id=>3, :date=>"2022/01/03"},
|
72
|
+
# {:id=>4, :date=>"2022/1/2"},
|
73
|
+
# {:id=>1, :date=>"2022/1/1"}
|
74
|
+
# ]
|
75
|
+
|
39
76
|
```
|
40
77
|
|
41
78
|
## Contributing
|
data/Rakefile
CHANGED
data/lib/natural_sort_jp.rb
CHANGED
@@ -15,8 +15,13 @@ module NaturalSortJp
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.convert(title)
|
18
|
-
elements = title.to_s.
|
19
|
-
|
18
|
+
elements = title.to_s.scan(/([^0-90-9]*)([0-90-9]*)/).flatten
|
19
|
+
converted = []
|
20
|
+
elements.each do |t|
|
21
|
+
next if t.empty?
|
22
|
+
converted << Element.new(t)
|
23
|
+
end
|
24
|
+
converted
|
20
25
|
end
|
21
26
|
|
22
27
|
def self.referenced_by_attribute(obj, attribute)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: natural_sort_jp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thehighhigh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|