naturalsorter 0.5.11 → 0.7.11

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2012 Robert Reiz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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', '0.5.11'`
79
+ `gem 'naturalsorter', '0.7.11'`
80
80
 
81
81
  and run this command in your app root directory
82
82
 
data/lib/natcmp.rb CHANGED
@@ -73,4 +73,4 @@ def self.natcmp(str1, str2, caseInsensitive=false)
73
73
  return 0
74
74
  end
75
75
 
76
- end
76
+ end
@@ -1,3 +1,3 @@
1
1
  module Naturalsorter
2
- VERSION = "0.5.11"
3
- end
2
+ VERSION = "0.7.11"
3
+ end
data/lib/naturalsorter.rb CHANGED
@@ -92,24 +92,32 @@ module Naturalsorter
92
92
  end
93
93
 
94
94
  def self.bigger?(a, b)
95
+ Versioncmp.replace_leading_v( a )
96
+ Versioncmp.replace_leading_v( b )
95
97
  return false if a.eql?(b)
96
98
  newest = Sorter.get_newest_version(a, b)
97
99
  newest.eql?(a)
98
100
  end
99
101
 
100
102
  def self.bigger_or_equal?(a, b)
103
+ Versioncmp.replace_leading_v( a )
104
+ Versioncmp.replace_leading_v( b )
101
105
  return true if a.eql?(b)
102
106
  newest = Sorter.get_newest_version(a, b)
103
107
  newest.eql?(a)
104
108
  end
105
109
 
106
110
  def self.smaller?(a, b)
111
+ Versioncmp.replace_leading_v( a )
112
+ Versioncmp.replace_leading_v( b )
107
113
  return false if a.eql?(b)
108
114
  newest = Sorter.get_newest_version(a, b)
109
115
  newest.eql?(b)
110
116
  end
111
117
 
112
118
  def self.smaller_or_equal?(a, b)
119
+ Versioncmp.replace_leading_v( a )
120
+ Versioncmp.replace_leading_v( b )
113
121
  return true if a.eql?(b)
114
122
  newest = Sorter.get_newest_version(a, b)
115
123
  newest.eql?(b)
@@ -151,4 +159,4 @@ module Naturalsorter
151
159
 
152
160
  end
153
161
 
154
- end
162
+ end
@@ -13,4 +13,4 @@ class ReleaseRecognizer
13
13
  !value.match(/.+SNAPSHOT.*/i) and !value.match(/.+M.+/i)
14
14
  end
15
15
 
16
- end
16
+ end
data/lib/versioncmp.rb CHANGED
@@ -40,19 +40,11 @@ class Versioncmp
40
40
  return -1
41
41
  end
42
42
 
43
- a = String.new(a_val)
44
- if a_val.match(/\.x-dev$/)
45
- a = a_val.gsub("x-dev", "9999999")
46
- elsif a_val.match(/-dev$/)
47
- a = a_val.gsub("-dev", ".9999999")
48
- end
43
+ a = do_x_dev_replacements a_val
44
+ b = do_x_dev_replacements b_val
49
45
 
50
- b = String.new(b_val)
51
- if b_val.match(/\.x-dev$/)
52
- b = b_val.gsub("x-dev", "9999999")
53
- elsif b_val.match(/-dev$/)
54
- b = b_val.gsub("-dev", ".9999999")
55
- end
46
+ replace_leading_v( a )
47
+ replace_leading_v( b )
56
48
 
57
49
  offset1 = 0;
58
50
  offset2 = 0;
@@ -220,4 +212,20 @@ class Versioncmp
220
212
  return part.length() == 8 && part.match(/^[0-9]+$/) != nil
221
213
  end
222
214
 
223
- end
215
+ def self.do_x_dev_replacements val
216
+ new_val = String.new(val)
217
+ if val.match(/\.x-dev$/)
218
+ new_val = val.gsub("x-dev", "9999999")
219
+ elsif val.match(/-dev$/)
220
+ new_val = val.gsub("-dev", ".9999999")
221
+ end
222
+ new_val
223
+ end
224
+
225
+ def self.replace_leading_v val
226
+ if val.match(/^v[0-9]+/)
227
+ val.gsub!(/^v/, "")
228
+ end
229
+ end
230
+
231
+ end
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = "naturalsorter"
7
7
  s.version = Naturalsorter::VERSION
8
8
  s.authors = ["reiz", "versioneye"]
9
- s.email = ["robert.reiz@gmx.com"]
9
+ s.email = ["reiz@versioneye.com"]
10
10
  s.homepage = "https://github.com/versioneye/naturalsorter"
11
11
  s.summary = %q{Sorting arrays in natural order}
12
12
  s.description = %q{This GEM is sorting Arrays in a natural order. a2 < a10}
@@ -126,7 +126,25 @@ describe Naturalsorter::Sorter do
126
126
  end
127
127
  it "returns 1.10" do
128
128
  Naturalsorter::Sorter.get_newest_version("1.10", "1.8").should eql("1.10")
129
- end
129
+ end
130
+ it "returns 1.10" do
131
+ Naturalsorter::Sorter.get_newest_version("1.10", "v1.0").should eql("1.10")
132
+ end
133
+ it "returns v1.10" do
134
+ Naturalsorter::Sorter.get_newest_version("v1.10", "v1.0").should eql("v1.10")
135
+ end
136
+ it "returns v1.10" do
137
+ Naturalsorter::Sorter.get_newest_version("v1.10", "1.0").should eql("v1.10")
138
+ end
139
+ it "returns 1.10.x-dev" do
140
+ Naturalsorter::Sorter.get_newest_version("1.10.x-dev", "1.10.1").should eql("1.10.x-dev")
141
+ end
142
+ it "returns still 1.10.x-dev" do
143
+ Naturalsorter::Sorter.get_newest_version("1.10.x-dev", "1.10.99").should eql("1.10.x-dev")
144
+ end
145
+ it "returns still 1.11.1" do
146
+ Naturalsorter::Sorter.get_newest_version("1.10.x-dev", "1.11.1").should eql("1.11.1")
147
+ end
130
148
 
131
149
  end
132
150
 
@@ -164,6 +182,12 @@ describe Naturalsorter::Sorter do
164
182
  it "returns true" do
165
183
  Naturalsorter::Sorter.bigger_or_equal?("2.20", "2.20").should be_true
166
184
  end
185
+ it "returns true" do
186
+ Naturalsorter::Sorter.bigger_or_equal?("v3.2.0", "3.2.0").should be_true
187
+ end
188
+ it "returns true" do
189
+ Naturalsorter::Sorter.bigger_or_equal?("v3.2.0", "3.1.0").should be_true
190
+ end
167
191
  it "returns false" do
168
192
  Naturalsorter::Sorter.bigger_or_equal?("2.20", "3.0").should be_false
169
193
  end
@@ -207,6 +231,9 @@ describe Naturalsorter::Sorter do
207
231
  it "returns true" do
208
232
  Naturalsorter::Sorter.smaller_or_equal?("2.20", "3.0").should be_true
209
233
  end
234
+ it "returns true" do
235
+ Naturalsorter::Sorter.smaller_or_equal?("2.20", "v3.0").should be_true
236
+ end
210
237
 
211
238
  end
212
239
 
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.5.11
4
+ version: 0.7.11
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: 2012-10-21 00:00:00.000000000 Z
13
+ date: 2013-02-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -30,13 +30,14 @@ dependencies:
30
30
  version: '2.6'
31
31
  description: This GEM is sorting Arrays in a natural order. a2 < a10
32
32
  email:
33
- - robert.reiz@gmx.com
33
+ - reiz@versioneye.com
34
34
  executables: []
35
35
  extensions: []
36
36
  extra_rdoc_files: []
37
37
  files:
38
38
  - .gitignore
39
39
  - Gemfile
40
+ - LICENSE
40
41
  - README.markdown
41
42
  - Rakefile
42
43
  - lib/natcmp.rb