naturalsorter 3.0.8 → 3.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2493a58a3718f52a619b22998d7cc68c43d21538
4
- data.tar.gz: 4800f0e8937b93116189ff66abda5fbd3ff9bb1b
3
+ metadata.gz: 26c550b34ce0dc4469c49e3e961b1b1c73821ddf
4
+ data.tar.gz: 941b2e7359ecedbe4d701eb29b9b5ecbd05164c2
5
5
  SHA512:
6
- metadata.gz: 59744980620cdd08dcf917e02644ff0ea0d996ec4cc67610e0c892fe411c1707b5f937f26bb319b551083ec40ba3592d52f342d638cccacf8a3c93fd9117eceb
7
- data.tar.gz: ffa9e83d9cbbc9bce05e3e8f8babe317302296d92ca3575be36de463389cf29b2cca586939cb572cde1665697ccbc87c506d072311d6e803250369249368366c
6
+ metadata.gz: 3def80a792398c9db5da56d468bd9558f861cb720143aee5441188a305e3eda19879a412e5e3ee995950e558826fe1effcb6f5835fee1ce321c6eee0e4dd633a
7
+ data.tar.gz: ede6284471e7032e9930d59243a3d3b304f8a323d2eb0a9e9f04613c7e469cf5b5f8b9c658a6bddff6881ecb3d18d38d523f4c6e3d21905b63dbaef7789bf759
@@ -1,3 +1,3 @@
1
1
  module Naturalsorter
2
- VERSION = "3.0.8"
2
+ VERSION = "3.0.9"
3
3
  end
data/lib/versioncmp.rb CHANGED
@@ -74,7 +74,7 @@ class Versioncmp
74
74
  elsif ( !part1.match(/^[0-9]+$/) && !part2.match(/^[0-9]+$/) )
75
75
  return self.compare_strings ab[0], ab[1], part1, part2
76
76
  else
77
- return self.compare_specia_cases part1, part2
77
+ return self.compare_special_cases part1, part2
78
78
  end
79
79
  end
80
80
 
@@ -97,9 +97,9 @@ class Versioncmp
97
97
  end
98
98
 
99
99
 
100
- def self.compare_specia_cases part1, part2
100
+ def self.compare_special_cases part1, part2
101
101
  result = Versioncmp.check_jquery_versioning(part1, part2)
102
- return result if result != nil
102
+ return result if !result.to_s.strip.empty?
103
103
 
104
104
  digit = part1 if part1.match(/\d/)
105
105
  return -1 if ( part1.match(/\d/) && part2.match(/#{digit}\S*patch\S*/) )
@@ -110,19 +110,44 @@ class Versioncmp
110
110
  if ( part1.match(/#\S*patch\S*/) && part2.match(/\S*patch\S*/) )
111
111
  return compare_string(part1, part2)
112
112
  end
113
-
113
+
114
114
  return 1 if ( part1.eql?("0") && part2.match(/^[a-zA-Z]+/) )
115
115
  return -1 if ( part2.eql?("0") && part1.match(/^[a-zA-Z]+/) )
116
116
  return -1 if ( part1.eql?("0") && part2.match(/^[1-9]+[-_a-zA-Z]+/) )
117
117
  return 1 if ( part2.eql?("0") && part1.match(/^[1-9]+[-_a-zA-Z]+/) )
118
- return 1 if ( part1.match(/^[0-9]+$/) && !part2.match(/^[0-9]+$/) )
118
+
119
+ pm1 = part1.match(/\A[0-9]+\z/)
120
+ pm2 = part2.match(/\A(\d+)(\w+)\z/i)
121
+ return 1 if ( pm1 && pm2 && pm2[1].eql?(part1) && VersionTagRecognizer.stable?(pm2[2]) )
122
+ return -1 if ( pm1 && pm2 && pm2[1].eql?(part1) && !VersionTagRecognizer.stable?(pm2[2]) )
123
+
124
+ pm1 = part1.match(/\A(\d+)-(\w+)\z/i)
125
+ pm2 = part2.match(/\A\d+\z/i)
126
+ return 1 if try_to_i_bigger( pm1, pm2, part2 )
127
+ return 1 if pm2 && pm1 && pm1[1].eql?(part2) && VersionTagRecognizer.stable?(pm1[2])
128
+
129
+ pm1 = part1.match(/\A\d+\z/i)
130
+ pm2 = part2.match(/\A(\d+)-(\w+)\z/i)
131
+ return 1 if try_to_i_bigger( pm1, pm2, part2 )
132
+ return -1 if pm1 && pm2 && pm2[1].eql?(part1) && VersionTagRecognizer.stable?(pm2[2])
133
+
134
+ return 1 if ( part1.match(/\A[0-9]+\z/) && !part2.match(/\A[0-9]+\z/) )
135
+
119
136
  return -1;
120
137
  rescue => e
121
138
  p e.message
139
+ p e.backtrace.join("\n")
122
140
  return -1
123
141
  end
124
142
 
125
143
 
144
+ def self.try_to_i_bigger pm1, pm2, part2
145
+ pm2 && pm1 && pm1[1].to_i > part2.to_i
146
+ rescue => e
147
+ false
148
+ end
149
+
150
+
126
151
  # Tags are RC, alpha, beta, dev and so on.
127
152
  #
128
153
  def self.check_for_tags(a, b)
@@ -34,6 +34,26 @@ describe Versioncmp do
34
34
  Versioncmp.compare("2.2.x-dev", "2.2.1").should eql(1)
35
35
  end
36
36
 
37
+ it "3.5.5-1 is bigger than 3.5.5" do
38
+ Versioncmp.compare("3.5.5-1", "3.5.5").should eql(1)
39
+ end
40
+
41
+ it "3.5.5 is smaller than 3.5.5-1 " do
42
+ Versioncmp.compare("3.5.5", "3.5.5-1").should eql(-1)
43
+ end
44
+
45
+ it "2.3.1-b01 is bigger than 2.3.1" do
46
+ Versioncmp.compare("2.3.1-b01", "2.3.1").should eql(1)
47
+ end
48
+
49
+ it "2.3.2-b01 is bigger than 2.3.1" do
50
+ Versioncmp.compare("2.3.2-b01", "2.3.1").should eql(1)
51
+ end
52
+
53
+ it "2.3.d-b01 is smaller than 2.3.1" do
54
+ Versioncmp.compare("2.3.d-b01", "2.3.1").should eql(-1)
55
+ end
56
+
37
57
  it "1.1 is smaller than 1.1.1" do
38
58
  Versioncmp.compare("1.1", "1.1.1").should eql(-1)
39
59
  end
@@ -155,7 +175,7 @@ describe Versioncmp do
155
175
  end
156
176
 
157
177
  it "1.7b is bigger than 1.7a" do
158
- Versioncmp.compare("1.7", "1.7b").should eql(1)
178
+ Versioncmp.compare("1.7b", "1.7a").should eql(1)
159
179
  end
160
180
 
161
181
  it "1.7.1rc1 is smaller than 1.7.2" do
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: 3.0.8
4
+ version: 3.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: 2015-06-03 00:00:00.000000000 Z
12
+ date: 2015-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  requirements: []
72
72
  rubyforge_project: naturalsorter
73
- rubygems_version: 2.4.7
73
+ rubygems_version: 2.4.8
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Sorting arrays in natural order