naturally 2.2.1 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71953ca154c0b7db095ccc5f8f877afed7142eb0bcf59a5118779ba2c8f79aa1
4
- data.tar.gz: 302ae86df325c4e526e1b8158dc669c497b27ae9b5ffe60d32bdcb206285eb46
3
+ metadata.gz: 9438825196cf2910c3580ac61f37ff9a38faa29df8c113268ccf2835ecc0736b
4
+ data.tar.gz: 7ea180458e34813435963b22fbed22e68a28c0d8ff025bf471116dc576e5eb88
5
5
  SHA512:
6
- metadata.gz: c7f607e695090c2d12a67b1410960312fbc4d9b7d046f1dea91513653fd00da13e01ebf92c1405efdb498a32029baae4733ddd022cee78becf67db7b4988bedd
7
- data.tar.gz: 3110d73168c9797628ad7490e1713785921abbce1651d54e9d8e1e2c6e2c65d9e5cbf77ad1c8b693ac49d2d4a7741ffb1198480f17a1f4b1fa9af2ca264d4c5f
6
+ metadata.gz: f74680fdecc119d32b2ad624f819972086961dd9d394b86f5f0897ec414a0fa12d1eec9902c0a207106423a011f7fedf8f277c90f91ffb053c2afeaa952925cc
7
+ data.tar.gz: f5f5979bb76c14ed2e5494043090d091eb17b5684930006291dfe7fb19c43544b629c0f84ec003d412c20e540075b7100f51309fd2c6113fb99f38f34bfa20ba
data/.travis.yml CHANGED
@@ -2,3 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 2.4
4
4
  - 2.5
5
+ - 2.6
6
+ - 2.7
data/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [2.3.0] - 2025-06-11
9
+
10
+ ### Added
11
+ - New `#sort_filenames` method for sorting filenames with underscores and dots as separators
12
+ - Dots are given higher priority than underscores in filename sorting
13
+ - Comprehensive test coverage for filename sorting scenarios
14
+
15
+ ### Changed
16
+ - Updated README with documentation and examples for the new `#sort_filenames` method
17
+
18
+ ## [2.2.2] - Previous Release
19
+
20
+ ### Notes
21
+ - Previous stable release
22
+ - Included support for natural sorting with legal numbering, course codes, and Unicode
23
+ - Maintained compatibility with Ruby 2.0+
24
+
25
+ ## Historical Releases
26
+
27
+ For releases prior to 2.2.2, please refer to the git commit history.
28
+
29
+ ---
30
+
31
+ **Note**: This changelog was introduced in version 2.3.0. Future releases will document all changes here.
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # Naturally
2
- [![Gem Version](https://badge.fury.io/rb/naturally.png)](http://badge.fury.io/rb/naturally) [![Build Status](https://travis-ci.org/public-law/naturally.png)](https://travis-ci.org/public-law/naturally)
3
- [![Maintainability](https://api.codeclimate.com/v1/badges/0ebf4ef97723f2622105/maintainability)](https://codeclimate.com/github/dogweather/naturally/maintainability)
2
+ [![Gem Version](https://badge.fury.io/rb/naturally.svg)](https://badge.fury.io/rb/naturally)
4
3
 
5
- Natural ("version number") sorting with support for **legal document numbering**, **college course codes**, and **Unicode**.
6
- See Jeff Atwood's [Sorting for Humans: Natural Sort Order](http://www.codinghorror.com/blog/2007/12/sorting-for-humans-natural-sort-order.html) and the Public.Law post [Counting to 10 in Californian](https://blog.public.law/2012/08/07/counting-from-1-to-10-in-californian/).
4
+ Natural ("version number") sorting with support for:
5
+
6
+ * **legal document numbering**,
7
+ * **college course codes**, and
8
+ * **Unicode**.
9
+
10
+ See Jeff Atwood's [Sorting for Humans: Natural Sort Order](https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/) and my post [Counting to 10 in Californian](https://blog.public.law/2012/08/07/counting-from-1-to-10-in-californian/).
7
11
 
8
12
  ## Installation
9
13
 
@@ -41,7 +45,7 @@ releases = [
41
45
  ]
42
46
 
43
47
  # Sort by version number
44
- sorted = Naturally.sort releases, by: :version
48
+ sorted = Naturally.sort(releases, by: :version)
45
49
 
46
50
  # Check what we have
47
51
  expect(sorted.map(&:name)).to eq [
@@ -54,7 +58,40 @@ expect(sorted.map(&:name)).to eq [
54
58
  ]
55
59
  ```
56
60
 
57
- [More examples are in the specs](https://github.com/dogweather/naturally/blob/master/spec/naturally_spec.rb).
61
+ [More examples are in the specs](https://github.com/public-law/naturally/blob/master/spec/naturally_spec.rb).
62
+
63
+
64
+ ## `#sort_filenames`
65
+
66
+ Sorts filenames naturally, treating underscores and dots as separators. Useful for sorting files like images or documents that use numbers, underscores, and dots in their names.
67
+
68
+ ```ruby
69
+ files = [
70
+ 'abc_2.tif',
71
+ 'abc_1_a.tif',
72
+ 'abc_1.zzz',
73
+ 'abc_1_xyz.abc',
74
+ 'abc_2a.tif',
75
+ 'abc.2.tif',
76
+ 'abc.1_a.tif',
77
+ 'abc_2.abc',
78
+ 'abc_1_xyz.abc'
79
+ ]
80
+ Naturally.sort_filenames(files)
81
+ # => [
82
+ # "abc.1_a.tif",
83
+ # "abc.2.tif",
84
+ # "abc_1.zzz",
85
+ # "abc_1_a.tif",
86
+ # "abc_1_xyz.abc",
87
+ # "abc_1_xyz.abc",
88
+ # "abc_2.abc",
89
+ # "abc_2.tif",
90
+ # "abc_2a.tif"
91
+ # ]
92
+ ```
93
+
94
+ This method gives higher priority to dots than underscores, so files like `abc.1_a.tif` will come before `abc.2.tif`.
58
95
 
59
96
 
60
97
  ## Implementation Notes
@@ -1,4 +1,4 @@
1
1
  module Naturally
2
2
  # Gem version
3
- VERSION = '2.2.1'
3
+ VERSION = '2.3.0'
4
4
  end
data/lib/naturally.rb CHANGED
@@ -49,6 +49,16 @@ module Naturally
49
49
  tokens.map { |t| Segment.new(t) }
50
50
  end
51
51
 
52
+ # Natural sort for filenames, treating underscores and dots as separators.
53
+ # Dots are given higher priority by inserting a '0' segment, as in user workaround.
54
+ # See Issue #24.
55
+ def self.sort_filenames(array)
56
+ array.sort_by do |filename|
57
+ # Replace '.' with '.0.' to give dot higher priority, then split on dot or underscore
58
+ filename.to_s.gsub('.', '.0.').split(/[\._]/).map { |t| Segment.new(t) }
59
+ end
60
+ end
61
+
52
62
  private
53
63
  # Sort an array of objects "naturally", yielding each object
54
64
  # to the block to obtain the sort key.
data/naturally.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["robb@public.law"]
11
11
  gem.summary = %q{Sorts numbers according to the way people are used to seeing them.}
12
12
  gem.description = %q{Natural Sorting with support for legal numbering, course numbers, and other number/letter mixes.}
13
- gem.homepage = "http://github.com/dogweather/naturally"
13
+ gem.homepage = "http://github.com/public-law/naturally"
14
14
  gem.required_ruby_version = '>= 2.0'
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
@@ -208,4 +208,16 @@ describe Naturally do
208
208
  ]
209
209
  end
210
210
  end
211
+
212
+ describe '#sort_filenames' do
213
+ it 'sorts filenames with underscores and dots as separators' do
214
+ expect(Naturally.sort_filenames(['abc_2.tif', 'abc_1_a.tif'])).to eq(["abc_1_a.tif", "abc_2.tif"])
215
+ expect(Naturally.sort_filenames(['abc_1.zzz', 'abc_1_xyz.abc'])).to eq(["abc_1.zzz", "abc_1_xyz.abc"])
216
+ expect(Naturally.sort_filenames(['abc_2a.tif', 'abc_1_a.tif'])).to eq(["abc_1_a.tif", "abc_2a.tif"])
217
+ expect(Naturally.sort_filenames(['abc.2.tif', 'abc.1_a.tif'])).to eq(["abc.1_a.tif", "abc.2.tif"])
218
+ expect(Naturally.sort_filenames(['abc_2.tif', 'abc_1.tif'])).to eq(["abc_1.tif", "abc_2.tif"])
219
+ expect(Naturally.sort_filenames(['abc_2.tif', 'abc_1_a.tif'])).to eq(["abc_1_a.tif", "abc_2.tif"])
220
+ expect(Naturally.sort_filenames(['abc_2.abc', 'abc_1_xyz.abc'])).to eq(["abc_1_xyz.abc", "abc_2.abc"])
221
+ end
222
+ end
211
223
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: naturally
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-01-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Natural Sorting with support for legal numbering, course numbers, and
14
13
  other number/letter mixes.
@@ -20,6 +19,7 @@ extra_rdoc_files: []
20
19
  files:
21
20
  - ".gitignore"
22
21
  - ".travis.yml"
22
+ - CHANGELOG.md
23
23
  - Gemfile
24
24
  - LICENSE.txt
25
25
  - README.md
@@ -29,11 +29,10 @@ files:
29
29
  - lib/naturally/version.rb
30
30
  - naturally.gemspec
31
31
  - spec/naturally_spec.rb
32
- homepage: http://github.com/dogweather/naturally
32
+ homepage: http://github.com/public-law/naturally
33
33
  licenses:
34
34
  - MIT
35
35
  metadata: {}
36
- post_install_message:
37
36
  rdoc_options: []
38
37
  require_paths:
39
38
  - lib
@@ -48,8 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
47
  - !ruby/object:Gem::Version
49
48
  version: '0'
50
49
  requirements: []
51
- rubygems_version: 3.2.5
52
- signing_key:
50
+ rubygems_version: 3.6.9
53
51
  specification_version: 4
54
52
  summary: Sorts numbers according to the way people are used to seeing them.
55
53
  test_files: