naturally 1.0.5 → 1.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 +4 -4
- data/.travis.yml +0 -2
- data/Gemfile.lock +2 -2
- data/lib/naturally/version.rb +1 -1
- data/lib/naturally.rb +10 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e088049af46b6400067b7fee29e5fcf173f867c5
|
4
|
+
data.tar.gz: 0f2c8c9786b402bf168826b416229c725805744b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0e08aedc2dcaadc4af03ed0ebe01b2ae60bfa1d0f87d950aec091d0a4c52fe02c69ec0b0d398b34f147b5b85b2f587d55429a710e4cdbab500a0dbe2fd7a788
|
7
|
+
data.tar.gz: ff7350582be9a879f06069d96fca4a9e0429fd610fa212eea2390d4d8815c527eb9132d87590b4aa2bb2844f256433624b116dd6fcbbbedeb55954405ec35bf4
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/lib/naturally/version.rb
CHANGED
data/lib/naturally.rb
CHANGED
@@ -1,26 +1,29 @@
|
|
1
|
-
require
|
1
|
+
require 'naturally/version'
|
2
2
|
|
3
3
|
module Naturally
|
4
|
-
|
5
4
|
# Perform a natural sort.
|
5
|
+
#
|
6
6
|
# @param [Array<String>] an_array the list of numbers to sort.
|
7
7
|
# @return [Array<String>] the numbers sorted naturally.
|
8
8
|
def self.sort(an_array)
|
9
|
-
return an_array.sort_by{ |x| normalize(x) }
|
9
|
+
return an_array.sort_by { |x| normalize(x) }
|
10
10
|
end
|
11
11
|
|
12
12
|
# Convert the given number into an object that can be sorted
|
13
|
-
# naturally.
|
13
|
+
# naturally. This object is an array of {NumberElement} instances.
|
14
|
+
#
|
14
15
|
# @param [String] number the number in complex form such as 1.2a.3.
|
15
16
|
# @return [Array<NumberElement>] an array of NumberElements which is
|
16
17
|
# able to be sorted naturally via a normal 'sort'.
|
17
18
|
def self.normalize(number)
|
18
|
-
number.to_s.scan(%r/[0-9a-zA-Z]+/o).map{|i| NumberElement.new(i)}
|
19
|
+
number.to_s.scan(%r/[0-9a-zA-Z]+/o).map { |i| NumberElement.new(i) }
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
22
|
private
|
23
23
|
|
24
|
+
# An entity which can be compared to other like elements for
|
25
|
+
# sorting in an array. It's an object representing
|
26
|
+
# a value which implements the {Comparable} interface.
|
24
27
|
class NumberElement
|
25
28
|
include Comparable
|
26
29
|
attr_accessor :val
|
@@ -69,5 +72,4 @@ module Naturally
|
|
69
72
|
end
|
70
73
|
end
|
71
74
|
end
|
72
|
-
|
73
|
-
end
|
75
|
+
end
|
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
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robb Shecter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Natural Sorting with support for legal numbering
|
14
14
|
email:
|
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
47
|
version: '0'
|
48
48
|
requirements: []
|
49
49
|
rubyforge_project:
|
50
|
-
rubygems_version: 2.1
|
50
|
+
rubygems_version: 2.2.1
|
51
51
|
signing_key:
|
52
52
|
specification_version: 4
|
53
53
|
summary: Sorts numbers according to the way people are used to seeing them.
|