natural_sort_jp 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 576ae58c108d4b0db825ec54466d2bdd04ff4bea067d0232ed0a279d5f3b8680
4
+ data.tar.gz: bdcc15aebf0562dfed95ac4807c66e16d10dbe8aebc3d850879e3c8adfdfbda5
5
+ SHA512:
6
+ metadata.gz: 2b5d4da03645efd69312a451d35585553595046ef4f16ec2f4132887680e4e52b22ab7f4cc58cf03cea49eb2de7223214fa9402ee15235687aa035df6d113fb1
7
+ data.tar.gz: c5bfd0fb25d3617aec1a23e2d871148f775105d3a2da17b48b5823a54e8112110786e042fa076188498e7104c3f7861b9539b9879cbd2b34369082e959ab090e
data/CHANGELOG.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in natural_sort_jp.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ natural_sort_jp (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.0)
11
+ json (2.6.3)
12
+ parallel (1.22.1)
13
+ parser (3.2.1.0)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.1.1)
16
+ rake (13.0.6)
17
+ regexp_parser (2.7.0)
18
+ rexml (3.2.5)
19
+ rspec (3.12.0)
20
+ rspec-core (~> 3.12.0)
21
+ rspec-expectations (~> 3.12.0)
22
+ rspec-mocks (~> 3.12.0)
23
+ rspec-core (3.12.1)
24
+ rspec-support (~> 3.12.0)
25
+ rspec-expectations (3.12.2)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.12.0)
28
+ rspec-mocks (3.12.3)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.12.0)
31
+ rspec-support (3.12.0)
32
+ rubocop (1.47.0)
33
+ json (~> 2.3)
34
+ parallel (~> 1.10)
35
+ parser (>= 3.2.0.0)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ regexp_parser (>= 1.8, < 3.0)
38
+ rexml (>= 3.2.5, < 4.0)
39
+ rubocop-ast (>= 1.26.0, < 2.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 2.4.0, < 3.0)
42
+ rubocop-ast (1.27.0)
43
+ parser (>= 3.2.1.0)
44
+ ruby-progressbar (1.13.0)
45
+ unicode-display_width (2.4.2)
46
+
47
+ PLATFORMS
48
+ x86_64-darwin-21
49
+
50
+ DEPENDENCIES
51
+ bundler (~> 2.4.6)
52
+ natural_sort_jp!
53
+ rake (~> 13.0)
54
+ rspec (~> 3.0)
55
+ rubocop (~> 1.47.0)
56
+
57
+ BUNDLED WITH
58
+ 2.4.6
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # NaturalSortJp
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.
4
+
5
+ By using this gem, you can realize the special sorting (natural sort) used in file explorers such as google drive.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/natural_sort_jp.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NaturalSortJp
4
+ class Element
5
+ include Comparable
6
+
7
+ SORT_PRIORITY = { int: 1, str: 2 }.freeze
8
+
9
+ def initialize(val)
10
+ val.tr!('0-9', '0-9') if val =~ /[0-9]/
11
+ @val = val
12
+ end
13
+
14
+ def <=>(other)
15
+ to_array <=> other.to_array
16
+ end
17
+
18
+ def to_array
19
+ if @val =~ /^(\p{Digit}+$)/
20
+ [SORT_PRIORITY[:int], @val.to_i]
21
+ else
22
+ [SORT_PRIORITY[:str], @val]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NaturalSortJp
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'natural_sort_jp/element'
4
+
5
+ module NaturalSortJp
6
+
7
+ def self.sort(array)
8
+ array.sort_by { |x| convert(x) }
9
+ end
10
+
11
+ def self.convert(title)
12
+ elements = title.to_s.gsub(/[0-90-9]+/, ',\&,').split(',')
13
+ elements.map { |t| Element.new(t) }
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/natural_sort_jp/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "natural_sort_jp"
7
+ spec.version = NaturalSortJp::VERSION
8
+ spec.authors = ["thehighhigh"]
9
+ spec.email = ["Yuto.ld.1017@gmail.com"]
10
+
11
+ spec.summary = "Natural Sort for Japanese."
12
+ spec.description = "You can use natural sort in japanese."
13
+ spec.homepage = "https://github.com/thehighhigh/natural_sort_jp"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/thehighhigh/natural_sort_jp"
20
+ spec.metadata["changelog_uri"] = "https://github.com/thehighhigh/natural_sort_jp/blob/main/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ spec.add_development_dependency "bundler", "~> 2.4.6"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency "rubocop", "~> 1.47.0"
38
+
39
+ # For more information and examples about making a new gem, check out our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ end
@@ -0,0 +1,4 @@
1
+ module NaturalSortJp
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: natural_sort_jp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - thehighhigh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.4.6
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.4.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.47.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.47.0
69
+ description: You can use natural sort in japanese.
70
+ email:
71
+ - Yuto.ld.1017@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - CHANGELOG.md
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - README.md
80
+ - Rakefile
81
+ - lib/natural_sort_jp.rb
82
+ - lib/natural_sort_jp/element.rb
83
+ - lib/natural_sort_jp/version.rb
84
+ - natural_sort_jp.gemspec
85
+ - sig/natural_sort_jp.rbs
86
+ homepage: https://github.com/thehighhigh/natural_sort_jp
87
+ licenses: []
88
+ metadata:
89
+ allowed_push_host: https://rubygems.org
90
+ homepage_uri: https://github.com/thehighhigh/natural_sort_jp
91
+ source_code_uri: https://github.com/thehighhigh/natural_sort_jp
92
+ changelog_uri: https://github.com/thehighhigh/natural_sort_jp/blob/main/CHANGELOG.md
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: 2.6.0
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.4.6
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Natural Sort for Japanese.
112
+ test_files: []