natural_sort_jp 0.1.0 → 0.2.0
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/README.md +21 -9
- data/lib/natural_sort_jp/element.rb +10 -2
- data/lib/natural_sort_jp/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6423ce38fe5c382b916dcbab85f70e7866cc55c22679f62b8d5d0384a40b8a0e
|
4
|
+
data.tar.gz: e135ba990b7a7ea8bcde936e68b35a789b0259b43a6dc9c1cf4d8b702301a87a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0b7099de4c68efbfca4ff8a8b12c387cf36a91ffc32998922bdbfe1c89c8bccd9f45c2dd45af034d56c1d1ccbcabeb46b1c66a2a703f51ee7a3ef5cb9ecfa3b
|
7
|
+
data.tar.gz: f868b9928ad667576badcfa8dfce189172729a7bbdc1a1269316ea2f8eebb7f184d4acc186b009dd7b54e6cab2de19e40b8536d935fc946b9529f365c20d52d2
|
data/README.md
CHANGED
@@ -1,25 +1,37 @@
|
|
1
1
|
# NaturalSortJp
|
2
2
|
|
3
|
-
natural_sort_jp can discriminate between full-width and half-width numbers, which are unique to the Japanese language, and perform natural sorting.
|
3
|
+
**natural_sort_jp** can discriminate between full-width and half-width numbers (zenkaku and hankaku), which are unique to the Japanese language, and perform natural sorting.
|
4
4
|
|
5
5
|
By using this gem, you can realize the special sorting (natural sort) used in file explorers such as google drive.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
```
|
10
|
+
$ gem install natural_sort_jp
|
11
|
+
```
|
10
12
|
|
11
|
-
|
13
|
+
## Usage
|
12
14
|
|
13
|
-
|
15
|
+
```ruby
|
16
|
+
require 'natural_sort_jp'
|
14
17
|
|
15
|
-
|
18
|
+
# Can use natural sort even if mix of zenkaku and hankaku.
|
16
19
|
|
17
|
-
|
20
|
+
NaturalSortJp.sort(
|
21
|
+
["第1回", "第2回", "第3回", "第10回", "第20回", "第21回"]
|
22
|
+
)
|
23
|
+
# => ["第1回", "第2回", "第3回", "第10回", "第20回", "第21回"]
|
18
24
|
|
19
|
-
## Usage
|
20
25
|
|
21
|
-
|
26
|
+
# It is not affected by the presence or absence of 0-filling.
|
27
|
+
|
28
|
+
NaturalSortJp.sort(
|
29
|
+
["2022/1/1", "2022/01/02", "2022/01/03", "2022/1/10", "2023/1/1"]
|
30
|
+
)
|
31
|
+
# => ["2022/1/1", "2022/01/02", "2022/01/03", "2022/1/10", "2023/1/1"]
|
32
|
+
|
33
|
+
```
|
22
34
|
|
23
35
|
## Contributing
|
24
36
|
|
25
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/thehighhigh/natural_sort_jp.
|
@@ -7,8 +7,7 @@ module NaturalSortJp
|
|
7
7
|
SORT_PRIORITY = { int: 1, str: 2 }.freeze
|
8
8
|
|
9
9
|
def initialize(val)
|
10
|
-
val
|
11
|
-
@val = val
|
10
|
+
@val = zenkaku2hankaku(val)
|
12
11
|
end
|
13
12
|
|
14
13
|
def <=>(other)
|
@@ -22,5 +21,14 @@ module NaturalSortJp
|
|
22
21
|
[SORT_PRIORITY[:str], @val]
|
23
22
|
end
|
24
23
|
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def zenkaku2hankaku(val)
|
28
|
+
val.tr!('0-9', '0-9') if val =~ /[0-9]/
|
29
|
+
val.tr!('a-z', 'a-z') if val =~ /[a-z]/
|
30
|
+
val.tr!('A-Z', 'A-Z') if val =~ /[A-Z]/
|
31
|
+
val
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|