naturalsorter 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Naturalsorter
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/versioncmp.rb CHANGED
@@ -37,10 +37,21 @@ 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
41
+ return -1
42
+ end
43
+ if part2.length() == 8 && part2.match(/^[0-9]+$/) != nil && part1.length() < 8
44
+ return 1
45
+ end
46
+
40
47
  offset1 += part1.length() + 1;
41
48
  offset2 += part2.length() + 1;
42
49
 
43
50
  if ( part1.match(/^[0-9]+$/) != nil && part2.match(/^[0-9]+$/) != nil )
51
+
52
+
53
+
54
+
44
55
  ai = part1.to_i;
45
56
  bi = part2.to_i;
46
57
  result = Versioncmp.compareInt(ai, bi);
@@ -64,6 +64,10 @@ describe Naturalsorter::Sorter do
64
64
  it "1.2, 1.1 is 1.1, 1.2" do
65
65
  Naturalsorter::Sorter.sort_version_desc(["0.4", "0.1", "1.1", "1.1.1", "1.2", "1.2.1", "1.0", "1.0.RC1"]).should eql(["1.2.1", "1.2", "1.1.1", "1.1", "1.0", "1.0.RC1", "0.4", "0.1"])
66
66
  end
67
+
68
+ it "sorts this to the end 20040121.140929" do
69
+ Naturalsorter::Sorter.sort_version_desc(["0.4", "0.1", "20040121.140929", "1.1.1", "1.2", "1.2.1", "1.0", "1.0.RC1"]).should eql(["1.2.1", "1.2", "1.1.1", "1.0", "1.0.RC1", "0.4", "0.1", "20040121.140929"])
70
+ end
67
71
 
68
72
  it "1.2, 1.1 is 1.1, 1.2" do
69
73
  Naturalsorter::Sorter.sort_version(["1.1", "1.2", "1.0"]).should eql(["1.0", "1.1", "1.2"])
@@ -45,5 +45,13 @@ describe Versioncmp do
45
45
  it "bigger RC than 1.0" do
46
46
  Versioncmp.compare("1.1.RC1", "1.1").should eql(-1)
47
47
  end
48
+
49
+ it "20040121.140929 is smaller than 1.1" do
50
+ Versioncmp.compare("20040121.140929", "1.1").should eql(-1)
51
+ end
52
+
53
+ it "1.1 is bigger than 20040121.140929" do
54
+ Versioncmp.compare("1.1", "20040121.140929").should eql(1)
55
+ end
48
56
 
49
57
  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.2
4
+ version: 0.2.3
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: &70101287446020 !ruby/object:Gem::Requirement
16
+ requirement: &70338427796540 !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: *70101287446020
24
+ version_requirements: *70338427796540
25
25
  description: This GEM is sorting Arrays in a natural order. a2 < a10
26
26
  email:
27
27
  - robert.reiz@gmx.com