naturalsorter 2.0.1 → 2.0.2
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.
- data/README.markdown +1 -1
- data/lib/naturalsorter/version.rb +1 -1
- data/lib/naturalsorter.rb +10 -10
- data/spec/naturalsorter_spec.rb +4 -0
- metadata +2 -2
data/README.markdown
CHANGED
data/lib/naturalsorter.rb
CHANGED
|
@@ -34,30 +34,28 @@ module Naturalsorter
|
|
|
34
34
|
if (array.nil? || array.empty?)
|
|
35
35
|
return nil
|
|
36
36
|
end
|
|
37
|
-
array.sort { |a,b| Natcmp.natcmp(a,b,caseinsesitive) }
|
|
37
|
+
array.sort { |a,b| Natcmp.natcmp(a, b, caseinsesitive) }
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def self.sort_desc(array, caseinsesitive)
|
|
41
41
|
if (array.nil? || array.empty?)
|
|
42
42
|
return nil
|
|
43
43
|
end
|
|
44
|
-
array.sort { |a, b| Natcmp.natcmp(b,a,caseinsesitive) }
|
|
44
|
+
array.sort { |a, b| Natcmp.natcmp(b, a, caseinsesitive) }
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
# 'Natural order' sort for an array of objects.
|
|
49
49
|
def self.sort_by_method(array, method, caseinsesitive)
|
|
50
|
-
if (array.nil? || array.empty?)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
array.sort { |a,b| Natcmp.natcmp(a.send(method),b.send(method),caseinsesitive) }
|
|
50
|
+
return nil if (array.nil? || array.empty?)
|
|
51
|
+
return nil if array.length == 1
|
|
52
|
+
array.sort { |a,b| Natcmp.natcmp( a.send(method), b.send(method), caseinsesitive) }
|
|
54
53
|
end
|
|
55
54
|
|
|
56
55
|
def self.sort_by_method_desc(array, method, caseinsesitive)
|
|
57
|
-
if (array.nil? || array.empty?)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
array.sort { |a, b| Natcmp.natcmp(b.send(method),a.send(method),caseinsesitive) }
|
|
56
|
+
return nil if (array.nil? || array.empty?)
|
|
57
|
+
return nil if array.length == 1
|
|
58
|
+
array.sort { |a, b| Natcmp.natcmp(b.send(method), a.send(method), caseinsesitive) }
|
|
61
59
|
end
|
|
62
60
|
|
|
63
61
|
|
|
@@ -75,11 +73,13 @@ module Naturalsorter
|
|
|
75
73
|
|
|
76
74
|
def self.sort_version_by_method(array, method)
|
|
77
75
|
return nil if (array.nil? || array.empty?)
|
|
76
|
+
return nil if array.length == 1
|
|
78
77
|
array.sort { |a,b| Versioncmp.compare(a.send(method), b.send(method)) }
|
|
79
78
|
end
|
|
80
79
|
|
|
81
80
|
def self.sort_version_by_method_desc(array, method)
|
|
82
81
|
return nil if (array.nil? || array.empty?)
|
|
82
|
+
return nil if array.length == 1
|
|
83
83
|
array.sort { |a,b| Versioncmp.compare(b.send(method), a.send(method)) }
|
|
84
84
|
end
|
|
85
85
|
|
data/spec/naturalsorter_spec.rb
CHANGED
|
@@ -32,6 +32,10 @@ describe Naturalsorter::Sorter do
|
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
describe "sort_version" do
|
|
35
|
+
|
|
36
|
+
it "1.1 is 1.1" do
|
|
37
|
+
Naturalsorter::Sorter.sort_version(["1.1"]).should eql(["1.1"])
|
|
38
|
+
end
|
|
35
39
|
|
|
36
40
|
it "1.1, 1.0 is 1.0, 1.1" do
|
|
37
41
|
Naturalsorter::Sorter.sort_version(["1.1", "1.0"]).should eql(["1.0", "1.1"])
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: naturalsorter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2013-
|
|
13
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: rspec
|