naturalsorter 2.0.8 → 2.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.ruby-version +1 -0
- data/.travis.yml +1 -1
- data/Gemfile +2 -4
- data/README.markdown +12 -10
- data/lib/naturalsorter/version.rb +1 -1
- data/lib/versioncmp.rb +19 -17
- data/naturalsorter.gemspec +1 -0
- data/spec/versioncmp_spec.rb +13 -1
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NTc2YzJjNDA5MjlhZDdmY2RjZTM5NjVkMzIzMjgwMTU0N2Q1ODEzYw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8e7c06f3c9ea76e81248a248f359ba9d47a19585
|
4
|
+
data.tar.gz: 4d61611758145d82ee30e137486c98a24ce7d176
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NTQ0NmQxZDExYzRmNTA2ZTJjYjRhZjYwYzRmNDk3M2M5ZGJkNTI2ZWEyMmNk
|
11
|
-
YWM1OTA5Yzk4MTNhYjRkODYwMDZjMWQ0MzlkMWZkNjVhMDFkOWE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MmY4NTYyNWE3MzhmMzgxMmJjMWMyZmRmZTI4MzRhZjVkYWEwYjE3NmM2YzE4
|
14
|
-
MmJjNDA1NzFhNjlkYjFkMjNmYzg5ZTJiNmM2ZDVhMTY2YzcxMmQ3YmZlZjFl
|
15
|
-
MDgyOTFjZDBiNjM0YjFkNTJjZTk2ODA3MWE3OWQ1NDFhMjdlZjI=
|
6
|
+
metadata.gz: 8bed886f7de1dc8a87178ef9affcc743eabb81fb3ff845bbc9b7d6873224421463e511be1379cfeb3696a2bc3502917103714a88e13c8c261c008c224e3452e8
|
7
|
+
data.tar.gz: 324bd9c146b24f4824ebcca9046b8faa05618b2616fd0cd5009b0ea142b4811add5afebd6c5220832e09616bdc22e7b9511c90fdc18161a3ee52f9d2610b60b1
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p353
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.markdown
CHANGED
@@ -20,6 +20,18 @@ Because the default sort method does not recognize the numbers in the string. Th
|
|
20
20
|
|
21
21
|
`["init20", "init30", "init200"]`
|
22
22
|
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
You should add this line to your Gemfile
|
27
|
+
|
28
|
+
`gem 'naturalsorter', '2.0.9'`
|
29
|
+
|
30
|
+
and run this command in your app root directory
|
31
|
+
|
32
|
+
`bundle install`
|
33
|
+
|
34
|
+
|
23
35
|
## Version Sorting
|
24
36
|
This fork contains some special algorithms to sort version numbers in a natural order. This project is used at <https://www.versioneye.com> to show versions of selected open source projects.
|
25
37
|
|
@@ -70,16 +82,6 @@ because '~>1.1' doesn't fit anymore the newest version.
|
|
70
82
|
`Naturalsorter::Sorter.is_version_current?(version, newest_version)`
|
71
83
|
|
72
84
|
|
73
|
-
## Installation
|
74
|
-
|
75
|
-
You should add this line to your Gemfile
|
76
|
-
|
77
|
-
`gem 'naturalsorter', '2.0.8'`
|
78
|
-
|
79
|
-
and run this command in your app root directory
|
80
|
-
|
81
|
-
`bundle install`
|
82
|
-
|
83
85
|
## How To Use - Examples
|
84
86
|
|
85
87
|
After the installation you can use it like this:
|
data/lib/versioncmp.rb
CHANGED
@@ -34,8 +34,8 @@ class Versioncmp
|
|
34
34
|
|
35
35
|
return 0 if a_empty && b_empty
|
36
36
|
return 0 if a_val.eql?( b_val )
|
37
|
-
return 1 if (a_empty == false) && b_empty
|
38
|
-
return -1 if (b_empty == false) && a_empty
|
37
|
+
return 1 if (a_empty == false) && (b_empty == true )
|
38
|
+
return -1 if (b_empty == false) && (a_empty == true )
|
39
39
|
|
40
40
|
a = pre_process a_val
|
41
41
|
b = pre_process b_val
|
@@ -43,7 +43,10 @@ class Versioncmp
|
|
43
43
|
ab = [a, b]
|
44
44
|
offsets = [0, 0]
|
45
45
|
|
46
|
-
|
46
|
+
max_length = a_val.length
|
47
|
+
max_length = b_val.length if b_val.length > max_length
|
48
|
+
|
49
|
+
for i in 0..max_length
|
47
50
|
result = self.check_the_slice ab, offsets
|
48
51
|
next if result.nil?
|
49
52
|
return result if result == 1 || result == -1
|
@@ -121,7 +124,7 @@ class Versioncmp
|
|
121
124
|
return Versioncmp.compare_string_length(a, b)
|
122
125
|
end
|
123
126
|
end
|
124
|
-
|
127
|
+
0
|
125
128
|
end
|
126
129
|
|
127
130
|
|
@@ -141,14 +144,12 @@ class Versioncmp
|
|
141
144
|
for z in 0..100
|
142
145
|
offsetz = offset + z
|
143
146
|
break if offsetz > cake.length()
|
147
|
+
|
144
148
|
p = cake[ offset..offset + z ]
|
145
|
-
if ( p.match(/^\w+\.$/) != nil )
|
146
|
-
break
|
147
|
-
end
|
148
|
-
end
|
149
|
-
if z > 0
|
150
|
-
z = z - 1
|
149
|
+
break if ( p.match(/^\w+\.$/) != nil )
|
151
150
|
end
|
151
|
+
|
152
|
+
z = z - 1 if z > 0
|
152
153
|
piece = cake[offset..offset + z ]
|
153
154
|
return piece
|
154
155
|
end
|
@@ -161,6 +162,7 @@ class Versioncmp
|
|
161
162
|
|
162
163
|
def self.pre_process val
|
163
164
|
cleaned_version = replace_x_dev val
|
165
|
+
cleaned_version = replace_wildcards cleaned_version
|
164
166
|
replace_leading_v cleaned_version
|
165
167
|
replace_99_does_not_exist cleaned_version
|
166
168
|
replace_timestamps cleaned_version
|
@@ -189,6 +191,13 @@ class Versioncmp
|
|
189
191
|
end
|
190
192
|
|
191
193
|
|
194
|
+
def self.replace_wildcards val
|
195
|
+
new_val = String.new(val)
|
196
|
+
new_val = "9999999" if val.match(/\.\*$/)
|
197
|
+
new_val
|
198
|
+
end
|
199
|
+
|
200
|
+
|
192
201
|
def self.replace_x_dev val
|
193
202
|
new_val = String.new(val)
|
194
203
|
if val.eql?("dev-master")
|
@@ -257,11 +266,4 @@ class Versioncmp
|
|
257
266
|
return -1
|
258
267
|
end
|
259
268
|
|
260
|
-
|
261
|
-
def self.compare_string_length_odd(a, b)
|
262
|
-
return 1 if a.length > b.length
|
263
|
-
return -1 if a.length < b.length
|
264
|
-
return 0
|
265
|
-
end
|
266
|
-
|
267
269
|
end
|
data/naturalsorter.gemspec
CHANGED
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["reiz", "versioneye"]
|
9
9
|
s.email = ["reiz@versioneye.com"]
|
10
10
|
s.homepage = "https://github.com/versioneye/naturalsorter"
|
11
|
+
s.license = 'MIT'
|
11
12
|
s.summary = %q{Sorting arrays in natural order}
|
12
13
|
s.description = %q{This GEM is sorting Arrays in a natural order. a2 < a10. Beside that this GEM has some methods to sort version strings. It even recognises alpha, beta, RC, dev and stable versions.}
|
13
14
|
|
data/spec/versioncmp_spec.rb
CHANGED
@@ -38,6 +38,18 @@ describe Versioncmp do
|
|
38
38
|
Versioncmp.compare("1.1", "1.1").should eql(0)
|
39
39
|
end
|
40
40
|
|
41
|
+
it "equal" do
|
42
|
+
Versioncmp.compare("1.0", "1.0.0").should eql(0)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "1.0.0 is smaller than 1.0.*" do
|
46
|
+
Versioncmp.compare("1.0.0", "1.0.*").should eql(-1)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "1.0 is smaller than 1.0.*" do
|
50
|
+
Versioncmp.compare("1.0.0", "1.0.*").should eql(-1)
|
51
|
+
end
|
52
|
+
|
41
53
|
it "equal RC" do
|
42
54
|
Versioncmp.compare("1.1.RC1", "1.1.RC1").should eql(0)
|
43
55
|
end
|
@@ -159,7 +171,7 @@ describe Versioncmp do
|
|
159
171
|
end
|
160
172
|
|
161
173
|
it "3.0.0 is equal to 3.0" do
|
162
|
-
Versioncmp.compare("3.0.0", "3.0").should eql(
|
174
|
+
Versioncmp.compare("3.0.0", "3.0").should eql(0)
|
163
175
|
end
|
164
176
|
|
165
177
|
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: 2.0.
|
4
|
+
version: 2.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- reiz
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-04-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -34,8 +34,9 @@ executables: []
|
|
34
34
|
extensions: []
|
35
35
|
extra_rdoc_files: []
|
36
36
|
files:
|
37
|
-
- .gitignore
|
38
|
-
- .
|
37
|
+
- ".gitignore"
|
38
|
+
- ".ruby-version"
|
39
|
+
- ".travis.yml"
|
39
40
|
- Gemfile
|
40
41
|
- LICENSE
|
41
42
|
- README.markdown
|
@@ -50,7 +51,8 @@ files:
|
|
50
51
|
- spec/version_tag_recognizer_spec.rb
|
51
52
|
- spec/versioncmp_spec.rb
|
52
53
|
homepage: https://github.com/versioneye/naturalsorter
|
53
|
-
licenses:
|
54
|
+
licenses:
|
55
|
+
- MIT
|
54
56
|
metadata: {}
|
55
57
|
post_install_message:
|
56
58
|
rdoc_options: []
|
@@ -58,17 +60,17 @@ require_paths:
|
|
58
60
|
- lib
|
59
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
60
62
|
requirements:
|
61
|
-
- -
|
63
|
+
- - ">="
|
62
64
|
- !ruby/object:Gem::Version
|
63
65
|
version: '0'
|
64
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
67
|
requirements:
|
66
|
-
- -
|
68
|
+
- - ">="
|
67
69
|
- !ruby/object:Gem::Version
|
68
70
|
version: '0'
|
69
71
|
requirements: []
|
70
72
|
rubyforge_project: naturalsorter
|
71
|
-
rubygems_version: 2.1.
|
73
|
+
rubygems_version: 2.1.11
|
72
74
|
signing_key:
|
73
75
|
specification_version: 4
|
74
76
|
summary: Sorting arrays in natural order
|