naturalsorter 0.2.0 → 0.2.1

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.0'`
52
+ `gem 'naturalsorter', '0.2.1'`
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.0"
3
- end
2
+ VERSION = "0.2.1"
3
+ end
data/lib/versioncmp.rb CHANGED
@@ -32,37 +32,28 @@ class Versioncmp
32
32
  offset2 = 0;
33
33
 
34
34
  for i in 0..100
35
- if offset1 >= a.length() || offset2 >= b.length()
36
- break
37
- end
35
+ break if offset1 >= a.length() || offset2 >= b.length()
38
36
 
39
37
  part1 = Versioncmp.getAPiece(offset1, a);
40
38
  part2 = Versioncmp.getAPiece(offset2, b);
39
+
40
+
41
41
  offset1 += part1.length() + 1;
42
42
  offset2 += part2.length() + 1;
43
43
 
44
44
  if ( part1.match(/^[0-9]+$/) != nil && part2.match(/^[0-9]+$/) != nil )
45
- ai = part1;
46
- bi = part2;
45
+ ai = part1.to_i;
46
+ bi = part2.to_i;
47
47
  result = Versioncmp.compareInt(ai, bi);
48
- if result != 0
49
- return result;
50
- else
51
- next
52
- end
48
+ return result if result != 0
49
+ next
53
50
  elsif ( part1.match(/^[0-9]+$/) == nil && part2.match(/^[0-9]+$/) == nil )
54
51
  result = Versioncmp.compareString(part1, part2)
55
- if (result != 0)
56
- return result
57
- else
58
- next
59
- end
52
+ return result if (result != 0)
53
+ next
60
54
  else
61
- if (part1.match(/^[0-9]+$/) != nil && part2.match(/^[0-9]+$/) == nil)
62
- return 1;
63
- else
64
- return -1;
65
- end
55
+ return 1 if (part1.match(/^[0-9]+$/) != nil && part2.match(/^[0-9]+$/) == nil)
56
+ return -1;
66
57
  end
67
58
  end
68
59
  result = Versioncmp.checkForRC(a, b)
@@ -122,9 +113,7 @@ class Versioncmp
122
113
  def self.getAPiece(offset, cake)
123
114
  for z in 0..100
124
115
  offsetz = offset + z
125
- if offsetz > cake.length()
126
- break
127
- end
116
+ break if offsetz > cake.length()
128
117
  p = cake[offset..offset + z]
129
118
  if ( p.match(/^[0-9]+$/) == nil )
130
119
  break
@@ -107,6 +107,10 @@ describe Naturalsorter::Sorter do
107
107
  it "returns 1.0" do
108
108
  Naturalsorter::Sorter.get_newest_version("1.0", "1.0").should eql("1.0")
109
109
  end
110
+ it "returns 1.10" do
111
+ Naturalsorter::Sorter.get_newest_version("1.10", "1.8").should eql("1.10")
112
+ end
113
+
110
114
 
111
115
  end
112
116
 
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.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70285480167460 !ruby/object:Gem::Requirement
16
+ requirement: &70304887095540 !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: *70285480167460
24
+ version_requirements: *70304887095540
25
25
  description: This GEM is sorting Arrays in a natural order. a2 < a10
26
26
  email:
27
27
  - robert.reiz@gmx.com