naturalsorter 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -76,7 +76,7 @@ because '~>1.1' doesn't fit anymore the newest version.
76
76
 
77
77
  You should add this line to your Gemfile
78
78
 
79
- `gem 'naturalsorter', '1.0.1'`
79
+ `gem 'naturalsorter', '2.0.0'`
80
80
 
81
81
  and run this command in your app root directory
82
82
 
@@ -88,7 +88,7 @@ After the installation you can use it like this:
88
88
 
89
89
  `Naturalsorter::Sorter.sort(["a400", "a5", "a1"], true)`
90
90
 
91
- it will return the array ["a1", "a5", "a400"].
91
+ it will return the array ["a1", "a5", "a400"]. The second paramter is for "caseinsesitive".
92
92
 
93
93
  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".
94
94
 
@@ -1,3 +1,3 @@
1
1
  module Naturalsorter
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/naturalsorter.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "naturalsorter/version"
2
2
  require "natcmp"
3
3
  require "versioncmp"
4
- require "release_recognizer"
4
+ require "version_tag_recognizer"
5
5
 
6
6
  # naturalsorter.rb
7
7
  #
@@ -158,61 +158,9 @@ module Naturalsorter
158
158
  end
159
159
 
160
160
  def self.replace_minimum_stability val
161
- Versioncmp.replace_minimum_stability val
161
+ VersionTagRecognizer.remove_minimum_stability val
162
162
  end
163
163
 
164
164
  end
165
-
166
- class ReleaseRecognizer
167
-
168
- def self.value_for( value )
169
- ReleaseRecognizer.value_for value
170
- end
171
-
172
- def self.compare_scopes( a, b)
173
- ReleaseRecognizer.compare_scopes(a, b)
174
- end
175
-
176
- def self.scoped? value
177
- ReleaseRecognizer.scoped? value
178
- end
179
-
180
- def self.remove_scope value
181
- ReleaseRecognizer.remove_scope value
182
- end
183
-
184
- def self.stable? value
185
- ReleaseRecognizer.stable? value
186
- end
187
-
188
- def self.alpha? value
189
- ReleaseRecognizer.alpha? value
190
- end
191
-
192
- def self.beta? value
193
- ReleaseRecognizer.beta? value
194
- end
195
-
196
- def self.dev? value
197
- ReleaseRecognizer.dev? value
198
- end
199
-
200
- def self.rc? value
201
- ReleaseRecognizer.rc? value
202
- end
203
-
204
- def self.snapshot? value
205
- ReleaseRecognizer.snapshot? value
206
- end
207
-
208
- def self.pre? value
209
- ReleaseRecognizer.pre? value
210
- end
211
-
212
- def self.jbossorg? value
213
- ReleaseRecognizer.jbossorg? value
214
- end
215
-
216
- end
217
165
 
218
166
  end
@@ -0,0 +1,174 @@
1
+ class VersionTagRecognizer
2
+
3
+ A_STABILITY_STABLE = "stable"
4
+ A_STABILITY_PRE = "pre"
5
+ A_STABILITY_RC = "RC"
6
+ A_STABILITY_BETA = "beta"
7
+ A_STABILITY_ALPHA = "alpha"
8
+ A_STABILITY_SNAPSHOT = "SNAPSHOT"
9
+ A_STABILITY_DEV = "dev"
10
+
11
+ def self.value_for( value )
12
+ return 0 if self.dev? value
13
+ return 2 if self.snapshot? value
14
+ return 3 if self.alpha? value
15
+ return 4 if self.beta? value
16
+ return 5 if self.rc? value
17
+ return 6 if self.pre? value
18
+ return 10 if self.stable? value
19
+ return 1
20
+ end
21
+
22
+ def self.compare_tags( a, b)
23
+ a_val = self.value_for a
24
+ b_val = self.value_for b
25
+ return -1 if a_val < b_val
26
+ return 1 if a_val > b_val
27
+ return 0
28
+ end
29
+
30
+ def self.tagged? value
31
+ self.alpha?(value) or self.beta?(value) or
32
+ self.dev?(value) or self.rc?(value) or
33
+ self.snapshot?(value) or self.pre?(value) or
34
+ self.jbossorg?(value)
35
+ end
36
+
37
+ def self.remove_tag value
38
+ if self.alpha? value
39
+ new_value = value.gsub(/\.[\w-]*alpha.*$/i, "")
40
+ return new_value.gsub(/\.[\w-]*a.*$/i, "")
41
+ elsif self.beta? value
42
+ new_value = value.gsub(/\.[\w-]*beta.*$/i, "")
43
+ return new_value.gsub(/\.[\w-]*b.*$/i, "")
44
+ elsif self.rc? value
45
+ return value.gsub(/\.[\w-]*rc.*$/i, "")
46
+ elsif self.pre? value
47
+ return value.gsub(/\.[\w-]*pre.*$/i, "")
48
+ elsif self.jbossorg? value
49
+ return value.gsub(/\.jbossorg.*$/i, "")
50
+ elsif self.snapshot? value
51
+ return value.gsub(/\.snapshot.*$/i, "")
52
+ end
53
+ return value
54
+ end
55
+
56
+ def self.remove_minimum_stability val
57
+ if val.match(/@.*$/)
58
+ val.gsub!(/@.*$/, "")
59
+ end
60
+ end
61
+
62
+ def self.does_it_fit_stability?( version_number, stability )
63
+ if stability.casecmp( A_STABILITY_STABLE ) == 0
64
+ if self.stable?( version_number )
65
+ return true
66
+ end
67
+ elsif stability.casecmp( A_STABILITY_PRE ) == 0
68
+ if self.stable?( version_number ) ||
69
+ self.pre?( version_number )
70
+ return true
71
+ end
72
+ elsif stability.casecmp( A_STABILITY_RC ) == 0
73
+ if self.stable?( version_number ) ||
74
+ self.rc?( version_number )
75
+ return true
76
+ end
77
+ elsif stability.casecmp( A_STABILITY_BETA ) == 0
78
+ if self.stable?( version_number ) ||
79
+ self.rc?( version_number ) ||
80
+ self.beta?( version_number )
81
+ return true
82
+ end
83
+ elsif stability.casecmp( A_STABILITY_ALPHA ) == 0
84
+ if self.stable?( version_number ) ||
85
+ self.rc?( version_number ) ||
86
+ self.beta?( version_number ) ||
87
+ self.alpha?( version_number )
88
+ return true
89
+ end
90
+ elsif stability.casecmp( A_STABILITY_SNAPSHOT ) == 0
91
+ if self.stable?( version_number ) ||
92
+ self.rc?( version_number ) ||
93
+ self.pre?( version_number ) ||
94
+ self.beta?( version_number ) ||
95
+ self.alpha?( version_number ) ||
96
+ self.snapshot?( version_number )
97
+ return true
98
+ end
99
+ elsif stability.casecmp( A_STABILITY_DEV ) == 0
100
+ return true
101
+ else
102
+ return false
103
+ end
104
+ end
105
+
106
+ def self.stability_tag_for( version )
107
+ if version.match(/@.*$/)
108
+ spliti = version.split("@")
109
+ return spliti[1]
110
+ else
111
+ if self.stable? version
112
+ return A_STABILITY_STABLE
113
+ elsif self.pre? version
114
+ return A_STABILITY_PRE
115
+ elsif self.rc? version
116
+ return A_STABILITY_RC
117
+ elsif self.beta? version
118
+ return A_STABILITY_BETA
119
+ elsif self.alpha? version
120
+ return A_STABILITY_ALPHA
121
+ elsif self.snapshot? version
122
+ return A_STABILITY_SNAPSHOT
123
+ else
124
+ return A_STABILITY_DEV
125
+ end
126
+ end
127
+ end
128
+
129
+ def self.release? value
130
+ self.stable? value
131
+ end
132
+
133
+ def self.stable? value
134
+ if value.match(/.+RELEASE.*/i) or value.match(/.+BUILD.*/i) or
135
+ value.match(/.+FINAL.*/i) or value.match(/.+SP.*/i) or
136
+ value.match(/.+GA.*/i)
137
+ return true
138
+ end
139
+ !self.alpha?(value) and !self.beta?(value) and
140
+ !self.dev?(value) and !self.pre?(value) and
141
+ !self.rc?(value) and !value.match(/.+SEC.*/i) and
142
+ !self.snapshot?(value) and !value.match(/.+M.+/i)
143
+ end
144
+
145
+ def self.alpha? value
146
+ return false if self.beta? value
147
+ value.match(/.*alpha.*/i) or value.match(/.+a.*/i)
148
+ end
149
+
150
+ def self.beta? value
151
+ value.match(/.*beta.*/i) or value.match(/.+b.*/i)
152
+ end
153
+
154
+ def self.dev? value
155
+ value.match(/.*dev.*/i)
156
+ end
157
+
158
+ def self.rc? value
159
+ value.match(/.*rc.*/i)
160
+ end
161
+
162
+ def self.snapshot? value
163
+ value.match(/.+SNAPSHOT.*/i)
164
+ end
165
+
166
+ def self.pre? value
167
+ value.match(/.*pre.*$/i)
168
+ end
169
+
170
+ def self.jbossorg? value
171
+ value.match(/.*jbossorg.*$/i)
172
+ end
173
+
174
+ end
data/lib/versioncmp.rb CHANGED
@@ -78,19 +78,21 @@ class Versioncmp
78
78
  return -1;
79
79
  end
80
80
  end
81
- result = Versioncmp.check_for_scopes(a, b)
81
+ result = Versioncmp.check_for_tags(a, b)
82
82
  return result
83
83
  end
84
84
 
85
- def self.check_for_scopes(a, b)
85
+ # Tags are RC, alpha, beta, dev and so on.
86
+ #
87
+ def self.check_for_tags(a, b)
86
88
  big = String.new(a)
87
89
  small = String.new(b)
88
90
  if (a.length() < b.length())
89
91
  big = String.new(b)
90
92
  small = String.new(a)
91
93
  end
92
- if (ReleaseRecognizer.scoped?(big))
93
- big_without_scope = ReleaseRecognizer.remove_scope big
94
+ if (VersionTagRecognizer.tagged?(big))
95
+ big_without_scope = VersionTagRecognizer.remove_tag big
94
96
  if (Versioncmp.compare_string(big_without_scope, small) == 0)
95
97
  return Versioncmp.compare_string_length(a, b)
96
98
  end
@@ -99,11 +101,11 @@ class Versioncmp
99
101
  end
100
102
 
101
103
  def self.double_scope_checker(a, b)
102
- if ReleaseRecognizer.scoped?(a) && ReleaseRecognizer.scoped?(b)
103
- a_without_scope = ReleaseRecognizer.remove_scope a
104
- b_without_scope = ReleaseRecognizer.remove_scope b
104
+ if VersionTagRecognizer.tagged?(a) && VersionTagRecognizer.tagged?(b)
105
+ a_without_scope = VersionTagRecognizer.remove_tag a
106
+ b_without_scope = VersionTagRecognizer.remove_tag b
105
107
  if a_without_scope.eql? b_without_scope
106
- return ReleaseRecognizer.compare_scopes(a, b)
108
+ return VersionTagRecognizer.compare_tags(a, b)
107
109
  end
108
110
  end
109
111
  0
@@ -132,7 +134,7 @@ class Versioncmp
132
134
  def self.pre_process val
133
135
  a = replace_x_dev val
134
136
  replace_leading_v( a )
135
- replace_minimum_stability( a )
137
+ VersionTagRecognizer.remove_minimum_stability( a )
136
138
  a
137
139
  end
138
140
 
@@ -154,11 +156,7 @@ class Versioncmp
154
156
  end
155
157
  end
156
158
 
157
- def self.replace_minimum_stability val
158
- if val.match(/@.*$/)
159
- val.gsub!(/@.*$/, "")
160
- end
161
- end
159
+
162
160
 
163
161
  def self.check_jquery_versioning(part1, part2)
164
162
  # --- START ---- special case for awesome jquery shitty verison numbers
@@ -0,0 +1,339 @@
1
+ require "naturalsorter"
2
+
3
+ describe VersionTagRecognizer do
4
+
5
+ it "release? is true" do
6
+ VersionTagRecognizer.release?("1.1").should be_true
7
+ end
8
+
9
+ it "release? is true" do
10
+ VersionTagRecognizer.release?("1.0.0").should be_true
11
+ end
12
+
13
+ it "release? is true" do
14
+ VersionTagRecognizer.release?("1").should be_true
15
+ end
16
+
17
+ it "release? is true" do
18
+ VersionTagRecognizer.release?("3.3.2.GA").should be_true
19
+ end
20
+
21
+ it "release? is true" do
22
+ VersionTagRecognizer.release?("4.1.5.SP1").should be_true
23
+ end
24
+
25
+ it "release? is true" do
26
+ VersionTagRecognizer.release?("3.1.0.RELEASE").should be_true
27
+ end
28
+
29
+ it "release? is true" do
30
+ VersionTagRecognizer.release?("3.2.0.BUILD").should be_true
31
+ end
32
+
33
+ it "release? is true" do
34
+ VersionTagRecognizer.release?("3.2.0buiLd").should be_true
35
+ end
36
+
37
+ it "release? is true" do
38
+ VersionTagRecognizer.release?("3.2.0.Final").should be_true
39
+ end
40
+
41
+ it "release? is true" do
42
+ VersionTagRecognizer.release?("3.2.0FINAL").should be_true
43
+ end
44
+
45
+ it "release? is false" do
46
+ VersionTagRecognizer.release?("1.1.pre").should be_false
47
+ end
48
+
49
+ it "release? is false" do
50
+ VersionTagRecognizer.release?("2.5.6.SEC03").should be_false
51
+ end
52
+
53
+ it "release? is false" do
54
+ VersionTagRecognizer.release?("2.3.8.pre1").should be_false
55
+ end
56
+
57
+ it "release? is false" do
58
+ VersionTagRecognizer.release?("2.3.9.pre").should be_false
59
+ end
60
+
61
+ it "release? is false" do
62
+ VersionTagRecognizer.release?("3.0.0.beta4").should be_false
63
+ end
64
+
65
+ it "release? is false" do
66
+ VersionTagRecognizer.release?("3.0.0.BETA4").should be_false
67
+ end
68
+
69
+ it "release? is false" do
70
+ VersionTagRecognizer.release?("3.0.0.beta").should be_false
71
+ end
72
+
73
+ it "release? is false" do
74
+ VersionTagRecognizer.release?("3.0.0.rc").should be_false
75
+ end
76
+
77
+ it "release? is false" do
78
+ VersionTagRecognizer.release?("3.0.0.rc2").should be_false
79
+ end
80
+
81
+ it "release? is false" do
82
+ VersionTagRecognizer.release?("3.0.0.RC2").should be_false
83
+ end
84
+
85
+ it "release? is false" do
86
+ VersionTagRecognizer.release?("2.0.x-dev").should be_false
87
+ end
88
+
89
+ it "release? is false" do
90
+ VersionTagRecognizer.release?("2.0.x-DEV").should be_false
91
+ end
92
+
93
+ it "release? is false" do
94
+ VersionTagRecognizer.release?("1.8b1").should be_false
95
+ end
96
+
97
+ it "release? is false" do
98
+ VersionTagRecognizer.release?("1.8B1").should be_false
99
+ end
100
+
101
+ it "release? is false" do
102
+ VersionTagRecognizer.release?("1.1.3a").should be_false
103
+ end
104
+
105
+ it "release? is false" do
106
+ VersionTagRecognizer.release?("1.1.3A").should be_false
107
+ end
108
+
109
+ it "release? is false" do
110
+ VersionTagRecognizer.release?("1.SNAPSHOT").should be_false
111
+ end
112
+
113
+ it "release? is false" do
114
+ VersionTagRecognizer.release?("1.snapshot").should be_false
115
+ end
116
+
117
+ it "release? is false" do
118
+ VersionTagRecognizer.release?("1.M1").should be_false
119
+ end
120
+
121
+ it "release? is false" do
122
+ VersionTagRecognizer.release?("2.0-m4").should be_false
123
+ end
124
+
125
+
126
+
127
+ it "is alpha? is true" do
128
+ VersionTagRecognizer.alpha?("2.0.alpha").should be_true
129
+ end
130
+
131
+ it "is alpha? is true" do
132
+ VersionTagRecognizer.alpha?("2.1.0alpha").should be_true
133
+ end
134
+
135
+ it "is alpha? is false" do
136
+ VersionTagRecognizer.alpha?("2.0.1").should be_false
137
+ end
138
+
139
+ it "is alpha? is false" do
140
+ VersionTagRecognizer.alpha?("2.1.0-BETA1").should be_false
141
+ end
142
+
143
+ it "is tagged? is true" do
144
+ VersionTagRecognizer.tagged?("2.1.0alpha").should be_true
145
+ end
146
+
147
+
148
+
149
+ it "remove_tag is right" do
150
+ VersionTagRecognizer.remove_tag("2.1.0alpha").should eql("2.1")
151
+ end
152
+ it "remove_tag is right" do
153
+ VersionTagRecognizer.remove_tag("2.1.1-BETA").should eql("2.1")
154
+ end
155
+ it "remove_tag is right" do
156
+ VersionTagRecognizer.remove_tag("2.1.1-RC").should eql("2.1")
157
+ end
158
+ it "remove_tag is right" do
159
+ VersionTagRecognizer.remove_tag("2.1.1-PRE").should eql("2.1")
160
+ end
161
+
162
+
163
+
164
+ it "is beta? is true" do
165
+ VersionTagRecognizer.beta?("2.0.beta").should be_true
166
+ end
167
+
168
+ it "is beta? is true" do
169
+ VersionTagRecognizer.beta?("2.1.0beta").should be_true
170
+ end
171
+
172
+ it "is beta? is false" do
173
+ VersionTagRecognizer.beta?("2.0.1").should be_false
174
+ end
175
+
176
+ it "is beta? is true" do
177
+ VersionTagRecognizer.beta?("2.2.0-BETA2").should be_true
178
+ end
179
+
180
+ it "is beta? is true" do
181
+ VersionTagRecognizer.beta?("2.1.0-BETA1").should be_true
182
+ end
183
+
184
+ it "is tagged? is true" do
185
+ VersionTagRecognizer.tagged?("2.1.0-BETA1").should be_true
186
+ end
187
+
188
+ it "remove_tag is right" do
189
+ VersionTagRecognizer.remove_tag("2.1.0-BETA1").should eql("2.1")
190
+ end
191
+
192
+
193
+
194
+ it "is dev? is true" do
195
+ VersionTagRecognizer.dev?("dev-master").should be_true
196
+ end
197
+
198
+ it "is dev? is true" do
199
+ VersionTagRecognizer.dev?("dev-progress-helper").should be_true
200
+ end
201
+
202
+ it "is dev? is true" do
203
+ VersionTagRecognizer.dev?("dev-deprecated").should be_true
204
+ end
205
+
206
+ it "is dev? is true" do
207
+ VersionTagRecognizer.dev?("2.2.x-dev").should be_true
208
+ end
209
+
210
+ it "is dev? is false" do
211
+ VersionTagRecognizer.dev?("2.0.1").should be_false
212
+ end
213
+
214
+
215
+
216
+ it "is rc? is true" do
217
+ VersionTagRecognizer.rc?("2.0.rc").should be_true
218
+ end
219
+
220
+ it "is rc? is true" do
221
+ VersionTagRecognizer.rc?("2.1.0rc").should be_true
222
+ end
223
+
224
+ it "is rc? is true" do
225
+ VersionTagRecognizer.rc?("2.2.0-RC3").should be_true
226
+ end
227
+
228
+ it "is rc? is false" do
229
+ VersionTagRecognizer.rc?("2.0.1").should be_false
230
+ end
231
+
232
+
233
+
234
+ it "is snapshot? is true" do
235
+ VersionTagRecognizer.snapshot?("2.0.snapshot").should be_true
236
+ end
237
+
238
+ it "is snapshot? is true" do
239
+ VersionTagRecognizer.snapshot?("2.1.0snapshot").should be_true
240
+ end
241
+
242
+ it "is snapshot? is true" do
243
+ VersionTagRecognizer.snapshot?("2.2.0-snapshot3").should be_true
244
+ end
245
+
246
+ it "is snapshot? is false" do
247
+ VersionTagRecognizer.snapshot?("2.0.1").should be_false
248
+ end
249
+
250
+
251
+ it "returns the right value for dev" do
252
+ VersionTagRecognizer.value_for("1.1.1-dev").should eql(0)
253
+ end
254
+ it "returns the right value for snapshot" do
255
+ VersionTagRecognizer.value_for("1.1.1-SNAPSHOT").should eql(2)
256
+ end
257
+ it "returns the right value for alpha" do
258
+ VersionTagRecognizer.value_for("1.1.1-alpha").should eql(3)
259
+ end
260
+ it "returns the right value for beta" do
261
+ VersionTagRecognizer.value_for("1.1.1-beta").should eql(4)
262
+ end
263
+ it "returns the right value for rc" do
264
+ VersionTagRecognizer.value_for("1.1.1-rc").should eql(5)
265
+ end
266
+ it "returns the right value for pre" do
267
+ VersionTagRecognizer.value_for("1.1.1-pre").should eql(6)
268
+ end
269
+ it "returns the right value for stable" do
270
+ VersionTagRecognizer.value_for("1.1.1").should eql(10)
271
+ end
272
+
273
+
274
+
275
+ it "returns compares right for alpha and beta" do
276
+ VersionTagRecognizer.compare_tags("1.1.1-alpha", "1.1.1-beta").should eql(-1)
277
+ end
278
+ it "returns compares right for beta and alpha" do
279
+ VersionTagRecognizer.compare_tags("1.1.1-beta", "1.1.1-alpha").should eql(1)
280
+ end
281
+ it "returns compares right for alpha and alpha" do
282
+ VersionTagRecognizer.compare_tags("1.1.1-alpha", "1.1.1-alpha").should eql(0)
283
+ end
284
+ it "returns compares right for RC and stable" do
285
+ VersionTagRecognizer.compare_tags("1.1.1-RC", "1.1.1").should eql(-1)
286
+ end
287
+ it "returns compares right for stable and dev" do
288
+ VersionTagRecognizer.compare_tags("1.1.1", "1.1.x-dev").should eql(1)
289
+ end
290
+
291
+
292
+
293
+ it "does fit stability" do
294
+ VersionTagRecognizer.does_it_fit_stability?( "2.2.1", "stable" ).should be_true
295
+ end
296
+ it "does not fit stability" do
297
+ VersionTagRecognizer.does_it_fit_stability?( "2.2.1-BETA", "stable" ).should be_false
298
+ end
299
+ it "does fit stability" do
300
+ VersionTagRecognizer.does_it_fit_stability?( "2.2.1-BETA", "alpha" ).should be_true
301
+ end
302
+ it "does fit stability" do
303
+ VersionTagRecognizer.does_it_fit_stability?( "2.2.1-BETA", "beta" ).should be_true
304
+ end
305
+ it "does fit stability" do
306
+ VersionTagRecognizer.does_it_fit_stability?( "2.2.x-dev", "dev" ).should be_true
307
+ end
308
+ it "does not fit stability" do
309
+ VersionTagRecognizer.does_it_fit_stability?( "2.2.x-dev", "alpha" ).should be_false
310
+ end
311
+ it "does not fit stability" do
312
+ VersionTagRecognizer.does_it_fit_stability?( "2.2.x-dev", "RC" ).should be_false
313
+ end
314
+ it "does fit stability" do
315
+ VersionTagRecognizer.does_it_fit_stability?( "2.2.1-RC", "RC" ).should be_true
316
+ end
317
+
318
+
319
+
320
+ it "stability_tag_for returns right" do
321
+ VersionTagRecognizer.stability_tag_for( "2.2.1").should eql(VersionTagRecognizer::A_STABILITY_STABLE)
322
+ end
323
+ it "stability_tag_for returns right" do
324
+ VersionTagRecognizer.stability_tag_for( "2.2.1-RC").should eql(VersionTagRecognizer::A_STABILITY_RC)
325
+ end
326
+ it "stability_tag_for returns right" do
327
+ VersionTagRecognizer.stability_tag_for( "2.2.1-BETA1").should eql(VersionTagRecognizer::A_STABILITY_BETA)
328
+ end
329
+ it "stability_tag_for returns right" do
330
+ VersionTagRecognizer.stability_tag_for( "2.2.1-alpha").should eql(VersionTagRecognizer::A_STABILITY_ALPHA)
331
+ end
332
+ it "stability_tag_for returns right" do
333
+ VersionTagRecognizer.stability_tag_for( "2.2.x-dev").should eql(VersionTagRecognizer::A_STABILITY_DEV)
334
+ end
335
+
336
+
337
+
338
+
339
+ end
@@ -25,6 +25,10 @@ describe Versioncmp do
25
25
  it "dev-master is bigger than 10.10.999" do
26
26
  Versioncmp.compare("dev-master", "10.10.999").should eql(1)
27
27
  end
28
+
29
+ it "2.2.x-dev is bigger than 2.2.1" do
30
+ Versioncmp.compare("2.2.x-dev", "2.2.1").should eql(1)
31
+ end
28
32
 
29
33
  it "1.1 is smaller than 1.1.1" do
30
34
  Versioncmp.compare("1.1", "1.1.1").should eql(-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: 1.0.1
4
+ version: 2.0.0
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-03-13 00:00:00.000000000 Z
13
+ date: 2013-03-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -43,11 +43,11 @@ files:
43
43
  - lib/natcmp.rb
44
44
  - lib/naturalsorter.rb
45
45
  - lib/naturalsorter/version.rb
46
- - lib/release_recognizer.rb
46
+ - lib/version_tag_recognizer.rb
47
47
  - lib/versioncmp.rb
48
48
  - naturalsorter.gemspec
49
49
  - spec/naturalsorter_spec.rb
50
- - spec/release_recognizer_spec.rb
50
+ - spec/version_tag_recognizer_spec.rb
51
51
  - spec/versioncmp_spec.rb
52
52
  homepage: https://github.com/versioneye/naturalsorter
53
53
  licenses: []
@@ -75,5 +75,5 @@ specification_version: 3
75
75
  summary: Sorting arrays in natural order
76
76
  test_files:
77
77
  - spec/naturalsorter_spec.rb
78
- - spec/release_recognizer_spec.rb
78
+ - spec/version_tag_recognizer_spec.rb
79
79
  - spec/versioncmp_spec.rb
@@ -1,93 +0,0 @@
1
- class ReleaseRecognizer
2
-
3
- def self.value_for( value )
4
- return 0 if self.dev? value
5
- return 2 if self.snapshot? value
6
- return 3 if self.pre? value
7
- return 4 if self.alpha? value
8
- return 5 if self.beta? value
9
- return 6 if self.rc? value
10
- return 10 if self.stable? value
11
- return 1
12
- end
13
-
14
- def self.compare_scopes( a, b)
15
- a_val = self.value_for a
16
- b_val = self.value_for b
17
- return -1 if a_val < b_val
18
- return 1 if a_val > b_val
19
- return 0
20
- end
21
-
22
- def self.scoped? value
23
- self.alpha?(value) or self.beta?(value) or
24
- self.dev?(value) or self.rc?(value) or
25
- self.snapshot?(value) or self.pre?(value) or
26
- self.jbossorg?(value)
27
- end
28
-
29
- def self.remove_scope value
30
- if self.alpha? value
31
- new_value = value.gsub(/\.[\w-]*alpha.*$/i, "")
32
- return new_value.gsub(/\.[\w-]*a.*$/i, "")
33
- elsif self.beta? value
34
- new_value = value.gsub(/\.[\w-]*beta.*$/i, "")
35
- return new_value.gsub(/\.[\w-]*b.*$/i, "")
36
- elsif self.rc? value
37
- return value.gsub(/\.[\w-]*rc.*$/i, "")
38
- elsif self.pre? value
39
- return value.gsub(/\.[\w-]*pre.*$/i, "")
40
- elsif self.jbossorg? value
41
- return value.gsub(/\.jbossorg.*$/i, "")
42
- elsif self.snapshot? value
43
- return value.gsub(/\.snapshot.*$/i, "")
44
- end
45
- return value
46
- end
47
-
48
- def self.release? value
49
- self.stable? value
50
- end
51
-
52
- def self.stable? value
53
- if value.match(/.+RELEASE.*/i) or value.match(/.+BUILD.*/i) or
54
- value.match(/.+FINAL.*/i) or value.match(/.+SP.*/i) or
55
- value.match(/.+GA.*/i)
56
- return true
57
- end
58
- !self.alpha?(value) and !self.beta?(value) and
59
- !self.dev?(value) and !self.pre?(value) and
60
- !self.rc?(value) and !value.match(/.+SEC.*/i) and
61
- !self.snapshot?(value) and !value.match(/.+M.+/i)
62
- end
63
-
64
- def self.alpha? value
65
- return false if self.beta? value
66
- value.match(/.*alpha.*/i) or value.match(/.+a.*/i)
67
- end
68
-
69
- def self.beta? value
70
- value.match(/.*beta.*/i) or value.match(/.+b.*/i)
71
- end
72
-
73
- def self.dev? value
74
- value.match(/.*dev.*/i)
75
- end
76
-
77
- def self.rc? value
78
- value.match(/.*rc.*/i)
79
- end
80
-
81
- def self.snapshot? value
82
- value.match(/.+SNAPSHOT.*/i)
83
- end
84
-
85
- def self.pre? value
86
- value.match(/.*pre.*$/i)
87
- end
88
-
89
- def self.jbossorg? value
90
- value.match(/.*jbossorg.*$/i)
91
- end
92
-
93
- end
@@ -1,240 +0,0 @@
1
- require "naturalsorter"
2
-
3
- describe ReleaseRecognizer do
4
-
5
- it "release? is true" do
6
- ReleaseRecognizer.release?("1.1").should be_true
7
- end
8
-
9
- it "release? is true" do
10
- ReleaseRecognizer.release?("1.0.0").should be_true
11
- end
12
-
13
- it "release? is true" do
14
- ReleaseRecognizer.release?("1").should be_true
15
- end
16
-
17
- it "release? is true" do
18
- ReleaseRecognizer.release?("3.3.2.GA").should be_true
19
- end
20
-
21
- it "release? is true" do
22
- ReleaseRecognizer.release?("4.1.5.SP1").should be_true
23
- end
24
-
25
- it "release? is true" do
26
- ReleaseRecognizer.release?("3.1.0.RELEASE").should be_true
27
- end
28
-
29
- it "release? is true" do
30
- ReleaseRecognizer.release?("3.2.0.BUILD").should be_true
31
- end
32
-
33
- it "release? is true" do
34
- ReleaseRecognizer.release?("3.2.0buiLd").should be_true
35
- end
36
-
37
- it "release? is true" do
38
- ReleaseRecognizer.release?("3.2.0.Final").should be_true
39
- end
40
-
41
- it "release? is true" do
42
- ReleaseRecognizer.release?("3.2.0FINAL").should be_true
43
- end
44
-
45
- it "release? is false" do
46
- ReleaseRecognizer.release?("1.1.pre").should be_false
47
- end
48
-
49
- it "release? is false" do
50
- ReleaseRecognizer.release?("2.5.6.SEC03").should be_false
51
- end
52
-
53
- it "release? is false" do
54
- ReleaseRecognizer.release?("2.3.8.pre1").should be_false
55
- end
56
-
57
- it "release? is false" do
58
- ReleaseRecognizer.release?("2.3.9.pre").should be_false
59
- end
60
-
61
- it "release? is false" do
62
- ReleaseRecognizer.release?("3.0.0.beta4").should be_false
63
- end
64
-
65
- it "release? is false" do
66
- ReleaseRecognizer.release?("3.0.0.BETA4").should be_false
67
- end
68
-
69
- it "release? is false" do
70
- ReleaseRecognizer.release?("3.0.0.beta").should be_false
71
- end
72
-
73
- it "release? is false" do
74
- ReleaseRecognizer.release?("3.0.0.rc").should be_false
75
- end
76
-
77
- it "release? is false" do
78
- ReleaseRecognizer.release?("3.0.0.rc2").should be_false
79
- end
80
-
81
- it "release? is false" do
82
- ReleaseRecognizer.release?("3.0.0.RC2").should be_false
83
- end
84
-
85
- it "release? is false" do
86
- ReleaseRecognizer.release?("2.0.x-dev").should be_false
87
- end
88
-
89
- it "release? is false" do
90
- ReleaseRecognizer.release?("2.0.x-DEV").should be_false
91
- end
92
-
93
- it "release? is false" do
94
- ReleaseRecognizer.release?("1.8b1").should be_false
95
- end
96
-
97
- it "release? is false" do
98
- ReleaseRecognizer.release?("1.8B1").should be_false
99
- end
100
-
101
- it "release? is false" do
102
- ReleaseRecognizer.release?("1.1.3a").should be_false
103
- end
104
-
105
- it "release? is false" do
106
- ReleaseRecognizer.release?("1.1.3A").should be_false
107
- end
108
-
109
- it "release? is false" do
110
- ReleaseRecognizer.release?("1.SNAPSHOT").should be_false
111
- end
112
-
113
- it "release? is false" do
114
- ReleaseRecognizer.release?("1.snapshot").should be_false
115
- end
116
-
117
- it "release? is false" do
118
- ReleaseRecognizer.release?("1.M1").should be_false
119
- end
120
-
121
- it "release? is false" do
122
- ReleaseRecognizer.release?("2.0-m4").should be_false
123
- end
124
-
125
-
126
-
127
- it "is alpha? is true" do
128
- ReleaseRecognizer.alpha?("2.0.alpha").should be_true
129
- end
130
-
131
- it "is alpha? is true" do
132
- ReleaseRecognizer.alpha?("2.1.0alpha").should be_true
133
- end
134
-
135
- it "is alpha? is false" do
136
- ReleaseRecognizer.alpha?("2.0.1").should be_false
137
- end
138
-
139
- it "is alpha? is false" do
140
- ReleaseRecognizer.alpha?("2.1.0-BETA1").should be_false
141
- end
142
-
143
- it "is scoped? is true" do
144
- ReleaseRecognizer.scoped?("2.1.0alpha").should be_true
145
- end
146
-
147
- it "remove_scope is right" do
148
- ReleaseRecognizer.remove_scope("2.1.0alpha").should eql("2.1")
149
- end
150
-
151
-
152
-
153
- it "is beta? is true" do
154
- ReleaseRecognizer.beta?("2.0.beta").should be_true
155
- end
156
-
157
- it "is beta? is true" do
158
- ReleaseRecognizer.beta?("2.1.0beta").should be_true
159
- end
160
-
161
- it "is beta? is false" do
162
- ReleaseRecognizer.beta?("2.0.1").should be_false
163
- end
164
-
165
- it "is beta? is true" do
166
- ReleaseRecognizer.beta?("2.2.0-BETA2").should be_true
167
- end
168
-
169
- it "is beta? is true" do
170
- ReleaseRecognizer.beta?("2.1.0-BETA1").should be_true
171
- end
172
-
173
- it "is scoped? is true" do
174
- ReleaseRecognizer.scoped?("2.1.0-BETA1").should be_true
175
- end
176
-
177
- it "remove_scope is right" do
178
- ReleaseRecognizer.remove_scope("2.1.0-BETA1").should eql("2.1")
179
- end
180
-
181
-
182
-
183
- it "is dev? is true" do
184
- ReleaseRecognizer.dev?("dev-master").should be_true
185
- end
186
-
187
- it "is dev? is true" do
188
- ReleaseRecognizer.dev?("dev-progress-helper").should be_true
189
- end
190
-
191
- it "is dev? is true" do
192
- ReleaseRecognizer.dev?("dev-deprecated").should be_true
193
- end
194
-
195
- it "is dev? is true" do
196
- ReleaseRecognizer.dev?("2.2.x-dev").should be_true
197
- end
198
-
199
- it "is dev? is false" do
200
- ReleaseRecognizer.dev?("2.0.1").should be_false
201
- end
202
-
203
-
204
-
205
- it "is rc? is true" do
206
- ReleaseRecognizer.rc?("2.0.rc").should be_true
207
- end
208
-
209
- it "is rc? is true" do
210
- ReleaseRecognizer.rc?("2.1.0rc").should be_true
211
- end
212
-
213
- it "is rc? is true" do
214
- ReleaseRecognizer.rc?("2.2.0-RC3").should be_true
215
- end
216
-
217
- it "is rc? is false" do
218
- ReleaseRecognizer.rc?("2.0.1").should be_false
219
- end
220
-
221
-
222
-
223
- it "is snapshot? is true" do
224
- ReleaseRecognizer.snapshot?("2.0.snapshot").should be_true
225
- end
226
-
227
- it "is snapshot? is true" do
228
- ReleaseRecognizer.snapshot?("2.1.0snapshot").should be_true
229
- end
230
-
231
- it "is snapshot? is true" do
232
- ReleaseRecognizer.snapshot?("2.2.0-snapshot3").should be_true
233
- end
234
-
235
- it "is snapshot? is false" do
236
- ReleaseRecognizer.snapshot?("2.0.1").should be_false
237
- end
238
-
239
-
240
- end