naturally 1.0.4 → 1.0.5

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
  SHA1:
3
- metadata.gz: 779c19dc2b8a8008edc6044aea5dd581d04fd231
4
- data.tar.gz: 51fc1ee3a6591b169e3823d38c26df50bb58c7ab
3
+ metadata.gz: faf607f415ddcf15c148739259c52e174b0b3b46
4
+ data.tar.gz: 1dc1552d7a19456bc2a94a7a5eea5fe27e034516
5
5
  SHA512:
6
- metadata.gz: 49b59c6d73db65805dc0e3d86fe7d8508e889d4634d0c9604e7fba9422e552c7dca242cdf34b0f8a534d912a3d1406a1d30d2d0ad6c7275c224871efc0087d85
7
- data.tar.gz: 5d996f19d784d877090477bc82e340035506f2f9dbebf4acc03156f43e84740459e9c2b8cc7602f9ea8e866191d229a3acee3b887a1b4456b54560df207ad3f3
6
+ metadata.gz: e8b3ff9491b77930b6f2aee7a839e1c7855d5df50808667704ba35a645cf35c98408a2949f51435e6782538b1ead608ec8b1cd320b93612ae0dfa7661195f615
7
+ data.tar.gz: 3b192cfda48fd177e3c3dc9575ec48d4ee856935d22723d7b0c740ba918b94d925886d04366c07860cb194a7bdd0091bd345e1bc987981ff49c50c978ffc6636
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ naturally (1.0.4)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.4)
10
+ rake (10.1.1)
11
+ rspec (2.14.1)
12
+ rspec-core (~> 2.14.0)
13
+ rspec-expectations (~> 2.14.0)
14
+ rspec-mocks (~> 2.14.0)
15
+ rspec-core (2.14.7)
16
+ rspec-expectations (2.14.4)
17
+ diff-lcs (>= 1.1.3, < 2.0)
18
+ rspec-mocks (2.14.4)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ naturally!
25
+ rake (~> 10.0)
26
+ rspec (~> 2.0)
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Naturally
2
- [![Build Status](https://travis-ci.org/dogweather/naturally.png)](https://travis-ci.org/dogweather/naturally)
2
+ [![Build Status](https://travis-ci.org/dogweather/naturally.png)](https://travis-ci.org/dogweather/naturally) [![Code Climate](https://codeclimate.com/github/dogweather/naturally.png)](https://codeclimate.com/github/dogweather/naturally)
3
3
 
4
4
  Natural sorting with added support for legal document numbering.
5
5
  See [Sorting for Humans : Natural Sort Order](http://www.codinghorror.com/blog/2007/12/sorting-for-humans-natural-sort-order.html) and [Counting to 10 in Californian](http://www.weblaws.org/blog/2012/08/counting-from-1-to-10-in-californian/)
@@ -9,6 +9,9 @@ The core of the search is [from here](https://github.com/ahoward/version_sorter)
9
9
  several changes to handle the particular types of numbers that come up in statutes, such
10
10
  as *335.1, 336, 336a*, etc.
11
11
 
12
+ `Naturally` will also sort "numbers" in college course code format such as
13
+ *MATH101, MATH102, ...*. See the specs for examples.
14
+
12
15
 
13
16
  ## Installation
14
17
 
data/lib/naturally.rb CHANGED
@@ -34,6 +34,8 @@ module Naturally
34
34
  return @val.to_i <=> other.val.to_i
35
35
  elsif numbers_with_letters? || other.numbers_with_letters?
36
36
  return simple_normalize(@val) <=> simple_normalize(other.val)
37
+ elsif letters_with_numbers? || other.letters_with_numbers?
38
+ return reverse_simple_normalize(@val) <=> reverse_simple_normalize(other.val)
37
39
  else
38
40
  return @val <=> other.val
39
41
  end
@@ -46,6 +48,10 @@ module Naturally
46
48
  def numbers_with_letters?
47
49
  val =~ /^\d+[a-zA-Z]+$/
48
50
  end
51
+
52
+ def letters_with_numbers?
53
+ val =~ /^[a-zA-Z]+\d+$/
54
+ end
49
55
 
50
56
  def simple_normalize(n)
51
57
  if n =~ /^(\d+)([a-zA-Z]+)$/
@@ -53,7 +59,15 @@ module Naturally
53
59
  else
54
60
  return [n.to_i]
55
61
  end
56
- end
62
+ end
63
+
64
+ def reverse_simple_normalize(n)
65
+ if n =~ /^([a-zA-Z]+)(\d+)$/
66
+ return [$1, $2.to_i]
67
+ else
68
+ return [n.to_s]
69
+ end
70
+ end
57
71
  end
58
72
 
59
73
  end
@@ -1,3 +1,3 @@
1
1
  module Naturally
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -25,6 +25,12 @@ describe Naturally do
25
25
  b = %w[335 335.1 336 336a 337 337.1 337.2 337.15 337a]
26
26
  Naturally.sort(a).should == b
27
27
  end
28
+
29
+ it 'sorts when letters have numbers in them' do
30
+ a = %w[PC1, PC3, PC5, PC7, PC9, PC10, PC11, PC12, PC13, PC14, PROF2, PBLI, SBP1, SBP3]
31
+ b = %w[PBLI, PC1, PC3, PC5, PC7, PC9, PC10, PC11, PC12, PC13, PC14, PROF2, SBP1, SBP3]
32
+ Naturally.sort(a).should == b
33
+ end
28
34
 
29
35
  it 'sorts double digits with letters correctly' do
30
36
  a = %w[12a 12b 12c 13a 13b 2 3 4 5 10 11 12]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: naturally
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-19 00:00:00.000000000 Z
11
+ date: 2014-01-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Natural Sorting with support for legal numbering
14
14
  email:
@@ -17,9 +17,10 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - .gitignore
21
- - .travis.yml
20
+ - ".gitignore"
21
+ - ".travis.yml"
22
22
  - Gemfile
23
+ - Gemfile.lock
23
24
  - LICENSE.txt
24
25
  - README.md
25
26
  - Rakefile
@@ -36,17 +37,17 @@ require_paths:
36
37
  - lib
37
38
  required_ruby_version: !ruby/object:Gem::Requirement
38
39
  requirements:
39
- - - '>='
40
+ - - ">="
40
41
  - !ruby/object:Gem::Version
41
42
  version: '0'
42
43
  required_rubygems_version: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - '>='
45
+ - - ">="
45
46
  - !ruby/object:Gem::Version
46
47
  version: '0'
47
48
  requirements: []
48
49
  rubyforge_project:
49
- rubygems_version: 2.1.2
50
+ rubygems_version: 2.1.11
50
51
  signing_key:
51
52
  specification_version: 4
52
53
  summary: Sorts numbers according to the way people are used to seeing them.