Skip to content
This repository
Browse code

important bugfix

  • Loading branch information...
commit 8e36fe4a825e9b5681eb19ddbf9b7e33fd1c1502 1 parent 8ec0ed5
authored
2  README.markdown
Source Rendered
@@ -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
 
4  lib/naturalsorter/version.rb
... ...
@@ -1,3 +1,3 @@
1 1
 module Naturalsorter
2  
-  VERSION = "0.2.0"
3  
-end
  2
+  VERSION = "0.2.1"
  3
+end
35  lib/versioncmp.rb
@@ -32,37 +32,28 @@ def self.compare(a, b)
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 @@ def self.isPre(a)
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
4  spec/naturalsorter_spec.rb
@@ -107,6 +107,10 @@
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
   

0 notes on commit 8e36fe4

Please sign in to comment.
Something went wrong with that request. Please try again.