Permalink
Browse files

important bugfix

  • Loading branch information...
1 parent 8ec0ed5 commit 8e36fe4a825e9b5681eb19ddbf9b7e33fd1c1502 reiz committed Apr 4, 2012
Showing with 19 additions and 26 deletions.
  1. +1 −1 README.markdown
  2. +2 −2 lib/naturalsorter/version.rb
  3. +12 −23 lib/versioncmp.rb
  4. +4 −0 spec/naturalsorter_spec.rb
View
2 README.markdown
@@ -49,7 +49,7 @@ Get newest.
You should add this line to your Gemfile
-`gem 'naturalsorter', '0.2.0'`
+`gem 'naturalsorter', '0.2.1'`
and run this command in your app root directory
View
4 lib/naturalsorter/version.rb
@@ -1,3 +1,3 @@
module Naturalsorter
- VERSION = "0.2.0"
-end
+ VERSION = "0.2.1"
+end
View
35 lib/versioncmp.rb
@@ -32,37 +32,28 @@ def self.compare(a, b)
offset2 = 0;
for i in 0..100
- if offset1 >= a.length() || offset2 >= b.length()
- break
- end
+ break if offset1 >= a.length() || offset2 >= b.length()
part1 = Versioncmp.getAPiece(offset1, a);
part2 = Versioncmp.getAPiece(offset2, b);
+
+
offset1 += part1.length() + 1;
offset2 += part2.length() + 1;
if ( part1.match(/^[0-9]+$/) != nil && part2.match(/^[0-9]+$/) != nil )
- ai = part1;
- bi = part2;
+ ai = part1.to_i;
+ bi = part2.to_i;
result = Versioncmp.compareInt(ai, bi);
- if result != 0
- return result;
- else
- next
- end
+ return result if result != 0
+ next
elsif ( part1.match(/^[0-9]+$/) == nil && part2.match(/^[0-9]+$/) == nil )
result = Versioncmp.compareString(part1, part2)
- if (result != 0)
- return result
- else
- next
- end
+ return result if (result != 0)
+ next
else
- if (part1.match(/^[0-9]+$/) != nil && part2.match(/^[0-9]+$/) == nil)
- return 1;
- else
- return -1;
- end
+ return 1 if (part1.match(/^[0-9]+$/) != nil && part2.match(/^[0-9]+$/) == nil)
+ return -1;
end
end
result = Versioncmp.checkForRC(a, b)
@@ -122,9 +113,7 @@ def self.isPre(a)
def self.getAPiece(offset, cake)
for z in 0..100
offsetz = offset + z
- if offsetz > cake.length()
- break
- end
+ break if offsetz > cake.length()
p = cake[offset..offset + z]
if ( p.match(/^[0-9]+$/) == nil )
break
View
4 spec/naturalsorter_spec.rb
@@ -107,6 +107,10 @@
it "returns 1.0" do
Naturalsorter::Sorter.get_newest_version("1.0", "1.0").should eql("1.0")
end
+ it "returns 1.10" do
+ Naturalsorter::Sorter.get_newest_version("1.10", "1.8").should eql("1.10")
+ end
+
end

0 comments on commit 8e36fe4

Please sign in to comment.