naturalsorter 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -49,7 +49,7 @@ Get newest.
49
49
 
50
50
  You should add this line to your Gemfile
51
51
 
52
- `gem 'naturalsorter', '0.2.2'`
52
+ `gem 'naturalsorter', '0.2.3'`
53
53
 
54
54
  and run this command in your app root directory
55
55
 
@@ -1,3 +1,3 @@
1
1
  module Naturalsorter
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
data/lib/versioncmp.rb CHANGED
@@ -37,10 +37,10 @@ class Versioncmp
37
37
  part1 = Versioncmp.getAPiece(offset1, a);
38
38
  part2 = Versioncmp.getAPiece(offset2, b);
39
39
 
40
- if part1.length() == 8 && part1.match(/^[0-9]+$/) != nil && part2.length() < 8
40
+ if Versioncmp.timestamp?(part1) && part2.length() < 8
41
41
  return -1
42
42
  end
43
- if part2.length() == 8 && part2.match(/^[0-9]+$/) != nil && part1.length() < 8
43
+ if Versioncmp.timestamp?(part2) && part1.length() < 8
44
44
  return 1
45
45
  end
46
46
 
@@ -48,10 +48,6 @@ class Versioncmp
48
48
  offset2 += part2.length() + 1;
49
49
 
50
50
  if ( part1.match(/^[0-9]+$/) != nil && part2.match(/^[0-9]+$/) != nil )
51
-
52
-
53
-
54
-
55
51
  ai = part1.to_i;
56
52
  bi = part2.to_i;
57
53
  result = Versioncmp.compareInt(ai, bi);
@@ -90,20 +86,35 @@ class Versioncmp
90
86
  small = String.new(a)
91
87
  end
92
88
  if (Versioncmp.isRc(big))
93
- bigwithoutRc = big.gsub(/\.RC[1-9]*$/, "").gsub(/\.rc[1-9]*$/, "")
89
+ bigwithoutRc = big.gsub(/\.rc.*$/i, "")
90
+ bigwithoutRc = bigwithoutRc.gsub(/\-rc.*$/i, "")
94
91
  if (Versioncmp.compareString(bigwithoutRc, small) == 0)
95
92
  return Versioncmp.getRcValue(a, b)
96
93
  end
97
94
  elsif (Versioncmp.isBeta(big))
98
- bigwithoutBeta = big.gsub(/\.BETA[1-9]*$/, "").gsub(/\.beta[1-9]*$/, "")
95
+ bigwithoutBeta = big.gsub(/\.beta[1-9]*$/i, "")
96
+ bigwithoutBeta = bigwithoutBeta.gsub(/\-beta[1-9]*$/i, "")
99
97
  if (Versioncmp.compareString(bigwithoutBeta, small) == 0)
100
98
  return Versioncmp.getRcValue(a, b)
101
99
  end
100
+ elsif (Versioncmp.isAlpha(big))
101
+ bigwithoutAlpha = big.gsub(/\.alpha[1-9]*$/i, "")
102
+ bigwithoutAlpha = bigwithoutAlpha.gsub(/\-alpha[1-9]*$/i, "")
103
+ if (Versioncmp.compareString(bigwithoutAlpha, small) == 0)
104
+ return Versioncmp.getRcValue(a, b)
105
+ end
102
106
  elsif (Versioncmp.isPre(big))
103
- bigwithoutPre = big.gsub(/\.PRE[1-9]*$/, "").gsub(/\.pre[1-9]*$/, "")
107
+ bigwithoutPre = big.gsub(/\.pre[1-9]*$/i, "")
108
+ bigwithoutPre = bigwithoutPre..gsub(/\-pre[1-9]*$/i, "")
104
109
  if (Versioncmp.compareString(bigwithoutPre, small) == 0)
105
110
  return Versioncmp.getRcValue(a, b)
106
111
  end
112
+ elsif (Versioncmp.isJbossorg(big))
113
+ bigwithoutRc = big.gsub(/\.jbossorg.*$/i, "")
114
+ bigwithoutRc = bigwithoutRc.gsub(/\-jbossorg.*$/i, "")
115
+ if (Versioncmp.compareString(bigwithoutRc, small) == 0)
116
+ return Versioncmp.getRcValue(a, b)
117
+ end
107
118
  end
108
119
  return 1 if a.length > b.length
109
120
  return -1 if a.length < b.length
@@ -111,15 +122,23 @@ class Versioncmp
111
122
  end
112
123
 
113
124
  def self.isRc(a)
114
- return a.match(/.*RC[1-9]*$/) != nil || a.match(/.*rc[1-9]*$/) != nil;
125
+ return a.match(/.*rc.*$/i) != nil;
126
+ end
127
+
128
+ def self.isJbossorg(a)
129
+ return a.match(/.*jbossorg.*$/i) != nil;
115
130
  end
116
131
 
117
132
  def self.isBeta(a)
118
- return a.match(/.*BETA[1-9]*$/) != nil || a.match(/.*beta[1-9]*$/) != nil;
133
+ return a.match(/.*beta[1-9]*$/i) != nil;
134
+ end
135
+
136
+ def self.isAlpha(a)
137
+ return a.match(/.*alpha[1-9]*$/i) != nil;
119
138
  end
120
139
 
121
140
  def self.isPre(a)
122
- return a.match(/.*PRE[1-9]*$/) != nil || a.match(/.*pre[1-9]*$/) != nil;
141
+ return a.match(/.*pre[1-9]*$/i) != nil;
123
142
  end
124
143
 
125
144
  def self.getAPiece(offset, cake)
@@ -142,5 +161,9 @@ class Versioncmp
142
161
  return 1 if (a.length() < b.length())
143
162
  return -1
144
163
  end
164
+
165
+ def self.timestamp?(part)
166
+ return part.length() == 8 && part.match(/^[0-9]+$/) != nil
167
+ end
145
168
 
146
169
  end
@@ -34,6 +34,26 @@ describe Versioncmp do
34
34
  Versioncmp.compare("1.1.rc1", "1.1").should eql(-1)
35
35
  end
36
36
 
37
+ it "smaller RC" do
38
+ Versioncmp.compare("1.1-rc1", "1.1").should eql(-1)
39
+ end
40
+
41
+ it "smaller alpha" do
42
+ Versioncmp.compare("1.1-alpha1", "1.1").should eql(-1)
43
+ end
44
+
45
+ it "smaller beta" do
46
+ Versioncmp.compare("3.1-beta1", "3.1").should eql(-1)
47
+ end
48
+
49
+ it "smaller 3.0-rc4-negotiate" do
50
+ Versioncmp.compare("3.0-rc4-negotiate", "3.0").should eql(-1)
51
+ end
52
+
53
+ it "smaller 3.1-jbossorg-1" do
54
+ Versioncmp.compare("3.1-jbossorg-1", "3.1").should eql(-1)
55
+ end
56
+
37
57
  it "bigger RC" do
38
58
  Versioncmp.compare("1.1.rc3", "1.1.rc2").should eql(1)
39
59
  end
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: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70338427796540 !ruby/object:Gem::Requirement
16
+ requirement: &70229582420100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '2.6'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70338427796540
24
+ version_requirements: *70229582420100
25
25
  description: This GEM is sorting Arrays in a natural order. a2 < a10
26
26
  email:
27
27
  - robert.reiz@gmx.com