naturalsorter 2.0.6 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.markdown +9 -10
- data/lib/naturalsorter/version.rb +1 -1
- data/lib/naturalsorter.rb +34 -46
- data/lib/versioncmp.rb +83 -41
- data/spec/naturalsorter_spec.rb +19 -0
- data/spec/versioncmp_spec.rb +41 -37
- metadata +5 -9
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZGI4NzU3ZjlhMDA0NjI2MTljODI5ZTFhMDU4MTlhMzU5ZjM2YmZiNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTEzYzdlYTRhMGVkNDg2MzU4MWUxN2UwMDExMzQwYTg3OTFkNzI2Mg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Y2E4YzFjYzI0MTIyZmRkY2IyMGM4NjcxYTIyOTVhMjM0NzliM2VjYjc5N2M0
|
10
|
+
ZjYwMTMyZWU1NmM0ZmM4Mjg3MTI4MGRiZGI5NDY0ZDU2NjgyNjllN2ZiZjA0
|
11
|
+
MDIyYTZjOWE3YmE4NTYyMGZiN2Q5MjJmMGNmODJhNzc4NmEyZWU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZTFhYWZjNGNjNmUzYmE0MTdmNWIzMjExYmEzM2JlM2U4NGJlMmEwYWU3Nzkz
|
14
|
+
NzU0MzdjODFkMTc3MGZlODVhMjY4YjU5YTVkNDg5ZDA5ZTNjZmU2NWJlYmVi
|
15
|
+
ZjU0YTg4ZGJhNTE0ZmRiZjdmNTM3ZmMxY2ZhZWQ3NmNjNjJkYzg=
|
data/README.markdown
CHANGED
@@ -26,19 +26,19 @@ This fork contains some special algorithms to sort version numbers in a natural
|
|
26
26
|
|
27
27
|
## API
|
28
28
|
|
29
|
-
|
29
|
+
These 2 methods are sorting a simple array of Strings. The name of the methods and the parameters are self explained.
|
30
30
|
|
31
|
-
`Naturalsorter::Sorter.sort(array,
|
31
|
+
`Naturalsorter::Sorter.sort(array, caseinsensitive = false, asc = true)`
|
32
32
|
|
33
33
|
And this here is for more advanced sorting. Where you can put in a array of objects and the method which should called on every object for comparison.
|
34
34
|
|
35
|
-
`Naturalsorter::Sorter.sort_by_method(array, method,
|
35
|
+
`Naturalsorter::Sorter.sort_by_method(array, method, caseinsensitive = false, asc = true)`
|
36
36
|
|
37
|
-
|
37
|
+
These methods are based on a different algorithm. Especially optimized for sorting version strings.
|
38
38
|
|
39
39
|
`Naturalsorter::Sorter.sort_version(array, asc = true)`
|
40
40
|
|
41
|
-
This here is again for an array with objects.
|
41
|
+
This here is again for an array with objects. Especially optimized for sorting version strings.
|
42
42
|
|
43
43
|
`Naturalsorter::Sorter.sort_version_by_method(array, method, asc = true )`
|
44
44
|
|
@@ -62,7 +62,7 @@ Is a smaller than b or equal?
|
|
62
62
|
|
63
63
|
`Naturalsorter::Sorter.smaller_or_equal?(a, b)`
|
64
64
|
|
65
|
-
This is for the Ruby GEM
|
65
|
+
This is for the Ruby GEM notation '~>'. For example '~>1.1' fits '1.2' and '1.9' and '1.14'. But not 2.0.
|
66
66
|
The parameter version would be for example '~>1.1' and the parameter newest_version would be the
|
67
67
|
current newest version of the GEM, for example "2.0". The method will return false in this case
|
68
68
|
because '~>1.1' doesn't fit anymore the newest version.
|
@@ -74,7 +74,7 @@ because '~>1.1' doesn't fit anymore the newest version.
|
|
74
74
|
|
75
75
|
You should add this line to your Gemfile
|
76
76
|
|
77
|
-
`gem 'naturalsorter', '2.0.
|
77
|
+
`gem 'naturalsorter', '2.0.7'`
|
78
78
|
|
79
79
|
and run this command in your app root directory
|
80
80
|
|
@@ -86,7 +86,7 @@ After the installation you can use it like this:
|
|
86
86
|
|
87
87
|
`Naturalsorter::Sorter.sort(["a400", "a5", "a1"], true)`
|
88
88
|
|
89
|
-
it will return the array ["a1", "a5", "a400"]. The second
|
89
|
+
it will return the array ["a1", "a5", "a400"]. The second parameter is for "caseinsensitive".
|
90
90
|
|
91
91
|
If you have more advanced objects you want to sort, you should use the second method. Assume you have a Class User with 3 attributes: "firstname", "lastname", "age" and you want to sort an array of class Users by "firstname".
|
92
92
|
|
@@ -103,5 +103,4 @@ will return the array ["1.1", "1.2", "1.10"]
|
|
103
103
|
|
104
104
|
## Alan Davies
|
105
105
|
|
106
|
-
The first 4 methods in this
|
107
|
-
|
106
|
+
The first 4 methods in this library are internal based on the natcmp implementation from Alan Davies. All glory to him for his awesome work.
|
data/lib/naturalsorter.rb
CHANGED
@@ -26,49 +26,37 @@ require "version_tag_recognizer"
|
|
26
26
|
# 3. This notice may not be removed or altered from any source distribution.
|
27
27
|
|
28
28
|
module Naturalsorter
|
29
|
-
|
29
|
+
|
30
30
|
class Sorter
|
31
|
-
|
32
|
-
def self.sort(array,
|
31
|
+
|
32
|
+
def self.sort(array, caseinsensitive = false , asc = true )
|
33
33
|
return array if (array.nil? || array.empty?)
|
34
|
-
if asc
|
35
|
-
|
36
|
-
else
|
37
|
-
return array.sort { |a, b| Natcmp.natcmp(b, a, caseinsesitive) }
|
38
|
-
end
|
34
|
+
return array.sort { |a, b| Natcmp.natcmp(a, b, caseinsensitive) } if asc
|
35
|
+
return array.sort { |a, b| Natcmp.natcmp(b, a, caseinsensitive) }
|
39
36
|
end
|
40
|
-
|
41
|
-
# 'Natural order' sort for an array of objects.
|
42
|
-
def self.sort_by_method(array, method,
|
37
|
+
|
38
|
+
# 'Natural order' sort for an array of objects.
|
39
|
+
def self.sort_by_method(array, method, caseinsensitive = false, asc = true)
|
43
40
|
return array if (array.nil? || array.empty? || array.length == 1)
|
44
|
-
if asc
|
45
|
-
|
46
|
-
else
|
47
|
-
array.sort { |a, b| Natcmp.natcmp(b.send(method), a.send(method), caseinsesitive) }
|
48
|
-
end
|
41
|
+
return array.sort { |a, b| Natcmp.natcmp( a.send(method), b.send(method), caseinsensitive) } if asc
|
42
|
+
return array.sort { |a, b| Natcmp.natcmp(b.send(method), a.send(method), caseinsensitive) }
|
49
43
|
end
|
50
|
-
|
51
|
-
|
44
|
+
|
45
|
+
|
52
46
|
def self.sort_version(array, asc = true)
|
53
47
|
return array if (array.nil? || array.empty? || array.length == 1)
|
54
|
-
if asc
|
55
|
-
|
56
|
-
else
|
57
|
-
array.sort { |a,b| Versioncmp.compare( b, a ) }
|
58
|
-
end
|
48
|
+
return array.sort { |a,b| Versioncmp.compare( a, b ) } if asc
|
49
|
+
return array.sort { |a,b| Versioncmp.compare( b, a ) }
|
59
50
|
end
|
60
|
-
|
61
|
-
|
51
|
+
|
52
|
+
|
62
53
|
def self.sort_version_by_method(array, method, asc = true )
|
63
54
|
return array if (array.nil? || array.empty? || array.length == 1 )
|
64
|
-
if asc
|
65
|
-
|
66
|
-
else
|
67
|
-
array.sort { |a,b| Versioncmp.compare(b.send(method), a.send(method)) }
|
68
|
-
end
|
55
|
+
return array.sort { |a,b| Versioncmp.compare(a.send(method), b.send(method)) } if asc
|
56
|
+
return array.sort { |a,b| Versioncmp.compare(b.send(method), a.send(method)) }
|
69
57
|
end
|
70
|
-
|
71
|
-
|
58
|
+
|
59
|
+
|
72
60
|
def self.get_newest_version(first, second)
|
73
61
|
array = [first, second]
|
74
62
|
array = array.sort { |a,b| Versioncmp.compare( a, b ) }
|
@@ -76,10 +64,10 @@ module Naturalsorter
|
|
76
64
|
end
|
77
65
|
|
78
66
|
def self.get_newest(a, b)
|
79
|
-
Versioncmp.replace_leading_vs a, b
|
67
|
+
Versioncmp.replace_leading_vs a, b
|
80
68
|
Sorter.get_newest_version(a, b)
|
81
69
|
end
|
82
|
-
|
70
|
+
|
83
71
|
def self.bigger?(a, b)
|
84
72
|
return false if a.eql?( b )
|
85
73
|
newest = self.get_newest a, b
|
@@ -91,23 +79,23 @@ module Naturalsorter
|
|
91
79
|
newest = self.get_newest a, b
|
92
80
|
newest.eql?( b )
|
93
81
|
end
|
94
|
-
|
82
|
+
|
95
83
|
def self.bigger_or_equal?(a, b)
|
96
84
|
return true if a.eql?(b)
|
97
85
|
newest = self.get_newest a, b
|
98
86
|
newest.eql?(a)
|
99
87
|
end
|
100
|
-
|
88
|
+
|
101
89
|
def self.smaller_or_equal?(a, b)
|
102
90
|
return true if a.eql?(b)
|
103
91
|
newest = self.get_newest a, b
|
104
92
|
newest.eql?(b)
|
105
|
-
end
|
93
|
+
end
|
94
|
+
|
106
95
|
|
107
|
-
|
108
|
-
|
109
|
-
#
|
110
|
-
# For example ~>1.1 fits 1.2 and 1.9 and 1.14
|
96
|
+
|
97
|
+
# This is for the GEM notaiton ~>
|
98
|
+
# For example ~>1.1 fits 1.2 and 1.9 and 1.14
|
111
99
|
# But not 2.0
|
112
100
|
def self.is_version_current?(version, newest_version)
|
113
101
|
version = version.gsub("~>", "")
|
@@ -121,7 +109,7 @@ module Naturalsorter
|
|
121
109
|
min_length = min_length - 2
|
122
110
|
if min_length < 0
|
123
111
|
min_length = 0
|
124
|
-
end
|
112
|
+
end
|
125
113
|
(0..min_length).each do |z|
|
126
114
|
ver = versions[z]
|
127
115
|
cur = newests[z]
|
@@ -139,10 +127,10 @@ module Naturalsorter
|
|
139
127
|
true
|
140
128
|
end
|
141
129
|
|
142
|
-
def self.replace_minimum_stability val
|
143
|
-
VersionTagRecognizer.remove_minimum_stability val
|
130
|
+
def self.replace_minimum_stability val
|
131
|
+
VersionTagRecognizer.remove_minimum_stability val
|
144
132
|
end
|
145
|
-
|
133
|
+
|
146
134
|
end
|
147
|
-
|
135
|
+
|
148
136
|
end
|
data/lib/versioncmp.rb
CHANGED
@@ -33,57 +33,85 @@ class Versioncmp
|
|
33
33
|
b_empty = b_val.nil? || b_val.empty?
|
34
34
|
|
35
35
|
return 0 if a_empty && b_empty
|
36
|
+
return 0 if a_val.eql?( b_val )
|
36
37
|
return 1 if (a_empty == false) && b_empty
|
37
38
|
return -1 if (b_empty == false) && a_empty
|
38
39
|
|
39
40
|
a = pre_process a_val
|
40
41
|
b = pre_process b_val
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
part1 = Versioncmp.get_a_piece_of_the_cake(offset1, a);
|
49
|
-
part2 = Versioncmp.get_a_piece_of_the_cake(offset2, b);
|
50
|
-
|
51
|
-
return -1 if Versioncmp.timestamp?(part1) && part2.length() < 8
|
52
|
-
return 1 if Versioncmp.timestamp?(part2) && part1.length() < 8
|
53
|
-
|
54
|
-
offset1 += part1.length() + 1;
|
55
|
-
offset2 += part2.length() + 1;
|
56
|
-
|
57
|
-
if ( part1.match(/^[0-9]+$/) && part2.match(/^[0-9]+$/) )
|
58
|
-
ai = part1.to_i;
|
59
|
-
bi = part2.to_i;
|
60
|
-
result = Versioncmp.compare_int(ai, bi);
|
61
|
-
return result if result != 0
|
62
|
-
next
|
63
|
-
elsif ( !part1.match(/^[0-9]+$/) && !part2.match(/^[0-9]+$/) )
|
64
|
-
result = double_scope_checker(a, b)
|
65
|
-
return result if result != 0
|
66
|
-
result = Versioncmp.compare_string(part1, part2)
|
67
|
-
return result if (result != 0)
|
68
|
-
next
|
69
|
-
else
|
70
|
-
result = Versioncmp.check_jquery_versioning(part1, part2)
|
71
|
-
return result if result != nil
|
72
|
-
return 1 if (part1.match(/^[0-9]+$/) && part2.match(/^[0-9]+$/) == nil)
|
73
|
-
return -1;
|
74
|
-
end
|
43
|
+
offsets = [0, 0]
|
44
|
+
|
45
|
+
for i in 0..20
|
46
|
+
result = self.check_the_slice a, b, offsets
|
47
|
+
next if result.nil?
|
48
|
+
return result if result == 1 || result == -1
|
75
49
|
end
|
76
50
|
result = Versioncmp.check_for_tags(a, b)
|
77
51
|
return result
|
78
52
|
end
|
79
53
|
|
54
|
+
|
55
|
+
def self.check_the_slice a, b, offsets
|
56
|
+
a += ".0" if offsets[0] >= a.length
|
57
|
+
b += ".0" if offsets[0] >= b.length
|
58
|
+
|
59
|
+
part1 = Versioncmp.get_a_piece_of_the_cake offsets[0], a
|
60
|
+
part2 = Versioncmp.get_a_piece_of_the_cake offsets[0], b
|
61
|
+
|
62
|
+
return -1 if Versioncmp.timestamp?(part1) && part2.length() < 8
|
63
|
+
return 1 if Versioncmp.timestamp?(part2) && part1.length() < 8
|
64
|
+
|
65
|
+
offsets[0] += part1.length() + 1;
|
66
|
+
offsets[1] += part2.length() + 1;
|
67
|
+
|
68
|
+
if ( part1.match(/^[0-9]+$/) && part2.match(/^[0-9]+$/) )
|
69
|
+
return self.compare_numbers part1, part2
|
70
|
+
elsif ( !part1.match(/^[0-9]+$/) && !part2.match(/^[0-9]+$/) )
|
71
|
+
return self.compare_strings a, b, part1, part2
|
72
|
+
else
|
73
|
+
return self.compare_specia_cases part1, part2
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def self.compare_numbers part1, part2
|
79
|
+
ai = part1.to_i;
|
80
|
+
bi = part2.to_i;
|
81
|
+
result = Versioncmp.compare_int(ai, bi);
|
82
|
+
return result if result == 1 || result == -1
|
83
|
+
return nil
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def self.compare_strings a, b, part1, part2
|
88
|
+
result = double_scope_checker(a, b)
|
89
|
+
return result if result == 1 || result == -1
|
90
|
+
result = Versioncmp.compare_string(part1, part2)
|
91
|
+
return result if result == 1 || result == -1
|
92
|
+
return nil
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
def self.compare_specia_cases part1, part2
|
97
|
+
result = Versioncmp.check_jquery_versioning(part1, part2)
|
98
|
+
return result if result != nil
|
99
|
+
return 1 if ( part1.eql?("0") && part2.match(/^[a-zA-Z]+/) )
|
100
|
+
return -1 if ( part2.eql?("0") && part1.match(/^[a-zA-Z]+/) )
|
101
|
+
return -1 if ( part1.eql?("0") && part2.match(/^[1-9]+[-_a-zA-Z]+/) )
|
102
|
+
return 1 if ( part2.eql?("0") && part1.match(/^[1-9]+[-_a-zA-Z]+/) )
|
103
|
+
return 1 if ( part1.match(/^[0-9]+$/) && !part2.match(/^[0-9]+$/) )
|
104
|
+
return -1;
|
105
|
+
end
|
106
|
+
|
107
|
+
|
80
108
|
# Tags are RC, alpha, beta, dev and so on.
|
81
109
|
#
|
82
110
|
def self.check_for_tags(a, b)
|
83
|
-
big
|
111
|
+
big = String.new(a)
|
84
112
|
small = String.new(b)
|
85
113
|
if (a.length() < b.length())
|
86
|
-
big
|
114
|
+
big = String.new(b)
|
87
115
|
small = String.new(a)
|
88
116
|
end
|
89
117
|
if (VersionTagRecognizer.tagged?(big))
|
@@ -95,6 +123,7 @@ class Versioncmp
|
|
95
123
|
self.compare_string_length_odd(a, b)
|
96
124
|
end
|
97
125
|
|
126
|
+
|
98
127
|
def self.double_scope_checker(a, b)
|
99
128
|
if VersionTagRecognizer.tagged?(a) && VersionTagRecognizer.tagged?(b)
|
100
129
|
a_without_scope = VersionTagRecognizer.remove_tag a
|
@@ -106,6 +135,7 @@ class Versioncmp
|
|
106
135
|
0
|
107
136
|
end
|
108
137
|
|
138
|
+
|
109
139
|
def self.get_a_piece_of_the_cake(offset, cake)
|
110
140
|
for z in 0..100
|
111
141
|
offsetz = offset + z
|
@@ -122,25 +152,29 @@ class Versioncmp
|
|
122
152
|
return piece
|
123
153
|
end
|
124
154
|
|
155
|
+
|
125
156
|
def self.timestamp?(part)
|
126
157
|
return part.length() == 8 && part.match(/^[0-9]+$/) != nil
|
127
158
|
end
|
128
159
|
|
160
|
+
|
129
161
|
def self.pre_process val
|
130
|
-
|
131
|
-
replace_leading_v
|
132
|
-
replace_99_does_not_exist
|
133
|
-
replace_timestamps
|
134
|
-
VersionTagRecognizer.remove_minimum_stability
|
135
|
-
|
162
|
+
cleaned_version = replace_x_dev val
|
163
|
+
replace_leading_v cleaned_version
|
164
|
+
replace_99_does_not_exist cleaned_version
|
165
|
+
replace_timestamps cleaned_version
|
166
|
+
VersionTagRecognizer.remove_minimum_stability cleaned_version
|
167
|
+
cleaned_version
|
136
168
|
end
|
137
169
|
|
170
|
+
|
138
171
|
def self.replace_99_does_not_exist val
|
139
172
|
if val.eql?("99.0-does-not-exist")
|
140
173
|
val.gsub!("99.0-does-not-exist", "0.0.0")
|
141
174
|
end
|
142
175
|
end
|
143
176
|
|
177
|
+
|
144
178
|
# Some glory Java Devs used the timestamp as version string
|
145
179
|
# http://www.versioneye.com/package/commons-beanutils--commons-beanutils
|
146
180
|
# Ganz grosses Kino !
|
@@ -153,6 +187,7 @@ class Versioncmp
|
|
153
187
|
end
|
154
188
|
end
|
155
189
|
|
190
|
+
|
156
191
|
def self.replace_x_dev val
|
157
192
|
new_val = String.new(val)
|
158
193
|
if val.eql?("dev-master")
|
@@ -165,15 +200,18 @@ class Versioncmp
|
|
165
200
|
new_val
|
166
201
|
end
|
167
202
|
|
203
|
+
|
168
204
|
def self.replace_leading_v val
|
169
205
|
val.gsub!(/^v/, "") if val.match(/^v[0-9]+/)
|
170
206
|
end
|
171
207
|
|
208
|
+
|
172
209
|
def self.replace_leading_vs a, b
|
173
210
|
self.replace_leading_v a
|
174
211
|
self.replace_leading_v b
|
175
212
|
end
|
176
213
|
|
214
|
+
|
177
215
|
def self.check_jquery_versioning(part1, part2)
|
178
216
|
# --- START ---- special case for awesome jquery shitty verison numbers
|
179
217
|
if ( part1.match(/^[0-9]+[a-zA-Z]+[0-9]+$/) != nil && part2.match(/^[0-9]+$/) != nil )
|
@@ -198,23 +236,27 @@ class Versioncmp
|
|
198
236
|
# --- END ---- special case for awesome jquery shitty verison numbers
|
199
237
|
end
|
200
238
|
|
239
|
+
|
201
240
|
def self.compare_int(ai, bi)
|
202
241
|
return -1 if (ai < bi)
|
203
242
|
return 0 if (ai == bi)
|
204
243
|
return 1
|
205
244
|
end
|
206
245
|
|
246
|
+
|
207
247
|
def self.compare_string(a, b)
|
208
248
|
return 0 if a.eql? b
|
209
249
|
return Natcmp.natcmp(a, b)
|
210
250
|
end
|
211
251
|
|
252
|
+
|
212
253
|
def self.compare_string_length(a, b)
|
213
254
|
return 0 if a.length() == b.length()
|
214
255
|
return 1 if a.length() < b.length()
|
215
256
|
return -1
|
216
257
|
end
|
217
258
|
|
259
|
+
|
218
260
|
def self.compare_string_length_odd(a, b)
|
219
261
|
return 1 if a.length > b.length
|
220
262
|
return -1 if a.length < b.length
|
data/spec/naturalsorter_spec.rb
CHANGED
@@ -6,6 +6,9 @@ describe Naturalsorter::Sorter do
|
|
6
6
|
it "cba is abc" do
|
7
7
|
Naturalsorter::Sorter.sort(["c", "b", "a"], true).should eql(["a", "b", "c"])
|
8
8
|
end
|
9
|
+
it "is 2.2, 2.2.1-b03" do
|
10
|
+
Naturalsorter::Sorter.sort(["2.2.1-b03", "2.2"], true).should eql(["2.2", "2.2.1-b03"])
|
11
|
+
end
|
9
12
|
it "c400b5a1 is a1b5c400" do
|
10
13
|
Naturalsorter::Sorter.sort(["a400", "a5", "a1"], true).should eql(["a1", "a5", "a400"])
|
11
14
|
end
|
@@ -41,6 +44,18 @@ describe Naturalsorter::Sorter do
|
|
41
44
|
Naturalsorter::Sorter.sort_version(["1.1", "20030211.134440"]).should eql(["20030211.134440", "1.1"])
|
42
45
|
end
|
43
46
|
|
47
|
+
it "is 2.2.0, 2.2.1-b03" do
|
48
|
+
Naturalsorter::Sorter.sort_version(["2.2.1-b03", "2.2.0", ]).should eql(["2.2.0", "2.2.1-b03"])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "is 2.2, 2.2.1-b03" do
|
52
|
+
Naturalsorter::Sorter.sort_version(["2.2.1-b03", "2.2", ]).should eql(["2.2", "2.2.1-b03"])
|
53
|
+
end
|
54
|
+
|
55
|
+
it "is 2.2.0-b03, 2.2.1-b03" do
|
56
|
+
Naturalsorter::Sorter.sort_version(["2.2.1-b03", "2.2.0-b03", ]).should eql(["2.2.0-b03", "2.2.1-b03"])
|
57
|
+
end
|
58
|
+
|
44
59
|
it "1.1, 1.0 is 1.0, 1.1" do
|
45
60
|
Naturalsorter::Sorter.sort_version(["1.1", "1.0"]).should eql(["1.0", "1.1"])
|
46
61
|
end
|
@@ -81,6 +96,10 @@ describe Naturalsorter::Sorter do
|
|
81
96
|
Naturalsorter::Sorter.sort_version(["1.1", "1.2", "1.0"]).should eql(["1.0", "1.1", "1.2"])
|
82
97
|
end
|
83
98
|
|
99
|
+
it "sort alphas and betas" do
|
100
|
+
Naturalsorter::Sorter.sort_version(["1.0.2", "1.0.1-b", "1.0.1-a"]).should eql(["1.0.1-a", "1.0.1-b", "1.0.2"])
|
101
|
+
end
|
102
|
+
|
84
103
|
it "sort with RC" do
|
85
104
|
Naturalsorter::Sorter.sort_version(["1.1", "1.1.RC1"]).should eql(["1.1.RC1", "1.1"])
|
86
105
|
end
|
data/spec/versioncmp_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "naturalsorter"
|
2
2
|
|
3
3
|
describe Versioncmp do
|
4
|
-
|
4
|
+
|
5
5
|
it "smaler" do
|
6
6
|
Versioncmp.compare("1.1", "1.2").should eql(-1)
|
7
7
|
end
|
@@ -13,11 +13,11 @@ describe Versioncmp do
|
|
13
13
|
it "smaler" do
|
14
14
|
Versioncmp.compare("1.1.5", "1.1-dev").should eql(-1)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "bigger" do
|
18
18
|
Versioncmp.compare("1.1", "1.0").should eql(1)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "1.1.1 is bigger than 1.1" do
|
22
22
|
Versioncmp.compare("1.1.1", "1.1").should eql(1)
|
23
23
|
end
|
@@ -26,26 +26,26 @@ describe Versioncmp do
|
|
26
26
|
Versioncmp.compare("dev-master", "10.10.999").should eql(1)
|
27
27
|
end
|
28
28
|
|
29
|
-
it "2.2.x-dev is bigger than 2.2.1" do
|
29
|
+
it "2.2.x-dev is bigger than 2.2.1" do
|
30
30
|
Versioncmp.compare("2.2.x-dev", "2.2.1").should eql(1)
|
31
|
-
end
|
32
|
-
|
31
|
+
end
|
32
|
+
|
33
33
|
it "1.1 is smaller than 1.1.1" do
|
34
34
|
Versioncmp.compare("1.1", "1.1.1").should eql(-1)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it "equal" do
|
38
38
|
Versioncmp.compare("1.1", "1.1").should eql(0)
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "equal RC" do
|
42
42
|
Versioncmp.compare("1.1.RC1", "1.1.RC1").should eql(0)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it "smaller RC" do
|
46
46
|
Versioncmp.compare("1.1.RC1", "1.1").should eql(-1)
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
it "smaller RC" do
|
50
50
|
Versioncmp.compare("1.1.rc1", "1.1").should eql(-1)
|
51
51
|
end
|
@@ -53,11 +53,11 @@ describe Versioncmp do
|
|
53
53
|
it "smaller RC" do
|
54
54
|
Versioncmp.compare("1.1.rc1", "2.0").should eql(-1)
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
it "smaller RC" do
|
58
58
|
Versioncmp.compare("1.1-rc1", "1.1").should eql(-1)
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
it "smaller alpha" do
|
62
62
|
Versioncmp.compare("1.1-alpha1", "1.1").should eql(-1)
|
63
63
|
end
|
@@ -65,93 +65,97 @@ describe Versioncmp do
|
|
65
65
|
it "alpha is smaller than BETA" do
|
66
66
|
Versioncmp.compare("2.1.0alpha", "2.1.0-BETA1").should eql(-1)
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
it "smaller alpha-1" do
|
70
70
|
Versioncmp.compare("1.1-alpha-1", "1.1").should eql(-1)
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
it "smaller alpha" do
|
74
74
|
Versioncmp.compare("1.1", "1.1-alpha-1").should eql(1)
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
it "smaller beta" do
|
78
78
|
Versioncmp.compare("3.1-beta1", "3.1").should eql(-1)
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it "smaller beta" do
|
82
82
|
Versioncmp.compare("3.1-beta-1", "3.1").should eql(-1)
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
it "smaller 3.0-rc4-negotiate" do
|
86
86
|
Versioncmp.compare("3.0-rc4-negotiate", "3.0").should eql(-1)
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
it "smaller 3.1-jbossorg-1" do
|
90
90
|
Versioncmp.compare("3.1-jbossorg-1", "3.1").should eql(-1)
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it "smaller 3.1-pre1" do
|
94
94
|
Versioncmp.compare("3.1-pre1", "3.1").should eql(-1)
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
it "bigger RC" do
|
98
98
|
Versioncmp.compare("1.1.rc3", "1.1.rc2").should eql(1)
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
it "bigger RC than 1.0" do
|
102
102
|
Versioncmp.compare("1.1.RC1", "1.0").should eql(1)
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
it "bigger RC than 1.0" do
|
106
106
|
Versioncmp.compare("1.1.RC1", "1.1").should eql(-1)
|
107
107
|
end
|
108
|
-
|
109
|
-
it "20040121.140929 is smaller than 1.1" do
|
108
|
+
|
109
|
+
it "20040121.140929 is smaller than 1.1" do
|
110
110
|
Versioncmp.compare("20040121.140929", "1.1").should eql(-1)
|
111
111
|
end
|
112
|
-
|
113
|
-
it "1.1 is bigger than 20040121.140929" do
|
112
|
+
|
113
|
+
it "1.1 is bigger than 20040121.140929" do
|
114
114
|
Versioncmp.compare("1.1", "20040121.140929").should eql(1)
|
115
115
|
end
|
116
116
|
|
117
|
-
it "1.7b2 is smaller than 1.7" do
|
117
|
+
it "1.7b2 is smaller than 1.7" do
|
118
118
|
Versioncmp.compare("1.7b2", "1.7").should eql(-1)
|
119
119
|
end
|
120
120
|
|
121
|
-
it "1.7 is bigger than 1.7b2" do
|
121
|
+
it "1.7 is bigger than 1.7b2" do
|
122
122
|
Versioncmp.compare("1.7", "1.7b2").should eql(1)
|
123
123
|
end
|
124
124
|
|
125
|
-
it "1.7 is bigger than 1.7rc2" do
|
125
|
+
it "1.7 is bigger than 1.7rc2" do
|
126
126
|
Versioncmp.compare("1.7", "1.7rc2").should eql(1)
|
127
127
|
end
|
128
128
|
|
129
|
-
it "1.7 is bigger than 1.7RC2" do
|
129
|
+
it "1.7 is bigger than 1.7RC2" do
|
130
130
|
Versioncmp.compare("1.7", "1.7RC2").should eql(1)
|
131
131
|
end
|
132
132
|
|
133
|
-
it "1.7 is bigger than 1.7a" do
|
133
|
+
it "1.7 is bigger than 1.7a" do
|
134
134
|
Versioncmp.compare("1.7", "1.7a").should eql(1)
|
135
135
|
end
|
136
136
|
|
137
|
-
it "1.7 is bigger than 1.7b" do
|
137
|
+
it "1.7 is bigger than 1.7b" do
|
138
138
|
Versioncmp.compare("1.7", "1.7b").should eql(1)
|
139
139
|
end
|
140
140
|
|
141
|
-
it "1.7b is bigger than 1.7a" do
|
141
|
+
it "1.7b is bigger than 1.7a" do
|
142
142
|
Versioncmp.compare("1.7", "1.7b").should eql(1)
|
143
143
|
end
|
144
144
|
|
145
|
-
it "1.7.1rc1 is smaller than 1.7.2" do
|
145
|
+
it "1.7.1rc1 is smaller than 1.7.2" do
|
146
146
|
Versioncmp.compare("1.7.1rc1", "1.7.2").should eql(-1)
|
147
147
|
end
|
148
148
|
|
149
|
-
it "1.7.2 is bigger than 1.7.1rc1" do
|
149
|
+
it "1.7.2 is bigger than 1.7.1rc1" do
|
150
150
|
Versioncmp.compare("1.7.2", "1.7.1rc1").should eql(1)
|
151
151
|
end
|
152
152
|
|
153
|
-
it "99.0-does-not-exist is smaller than 1.7.1" do
|
153
|
+
it "99.0-does-not-exist is smaller than 1.7.1" do
|
154
154
|
Versioncmp.compare("99.0-does-not-exist", "1.7.1").should eql(-1)
|
155
155
|
end
|
156
156
|
|
157
|
-
|
157
|
+
it "2.2.1-b03 is bigger then 2.2" do
|
158
|
+
Versioncmp.compare("2.2.1-b03", "2.2").should eql(1)
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: naturalsorter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- reiz
|
@@ -10,12 +9,11 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2013-
|
12
|
+
date: 2013-12-03 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rspec
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
18
|
- - '='
|
21
19
|
- !ruby/object:Gem::Version
|
@@ -23,7 +21,6 @@ dependencies:
|
|
23
21
|
type: :development
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
25
|
- - '='
|
29
26
|
- !ruby/object:Gem::Version
|
@@ -54,27 +51,26 @@ files:
|
|
54
51
|
- spec/versioncmp_spec.rb
|
55
52
|
homepage: https://github.com/versioneye/naturalsorter
|
56
53
|
licenses: []
|
54
|
+
metadata: {}
|
57
55
|
post_install_message:
|
58
56
|
rdoc_options: []
|
59
57
|
require_paths:
|
60
58
|
- lib
|
61
59
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
60
|
requirements:
|
64
61
|
- - ! '>='
|
65
62
|
- !ruby/object:Gem::Version
|
66
63
|
version: '0'
|
67
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
65
|
requirements:
|
70
66
|
- - ! '>='
|
71
67
|
- !ruby/object:Gem::Version
|
72
68
|
version: '0'
|
73
69
|
requirements: []
|
74
70
|
rubyforge_project: naturalsorter
|
75
|
-
rubygems_version: 1.
|
71
|
+
rubygems_version: 2.1.10
|
76
72
|
signing_key:
|
77
|
-
specification_version:
|
73
|
+
specification_version: 4
|
78
74
|
summary: Sorting arrays in natural order
|
79
75
|
test_files:
|
80
76
|
- spec/naturalsorter_spec.rb
|