Skip to content

Commit

Permalink
improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
reiz committed Apr 6, 2012
1 parent 9d1a5bd commit 13341b0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Get newest.


You should add this line to your Gemfile You should add this line to your Gemfile


`gem 'naturalsorter', '0.3.0'` `gem 'naturalsorter', '0.3.1'`


and run this command in your app root directory and run this command in your app root directory


Expand Down
2 changes: 1 addition & 1 deletion lib/naturalsorter/version.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,3 @@
module Naturalsorter module Naturalsorter
VERSION = "0.3.0" VERSION = "0.3.1"
end end
18 changes: 9 additions & 9 deletions lib/versioncmp.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -92,20 +92,20 @@ def self.checkForRC(a, b)
return Versioncmp.getRcValue(a, b) return Versioncmp.getRcValue(a, b)
end end
elsif (Versioncmp.isBeta(big)) elsif (Versioncmp.isBeta(big))
bigwithoutBeta = big.gsub(/\.beta[1-9]*$/i, "") bigwithoutBeta = big.gsub(/\.beta.*$/i, "")
bigwithoutBeta = bigwithoutBeta.gsub(/\-beta[1-9]*$/i, "") bigwithoutBeta = bigwithoutBeta.gsub(/\-beta.*$/i, "")
if (Versioncmp.compareString(bigwithoutBeta, small) == 0) if (Versioncmp.compareString(bigwithoutBeta, small) == 0)
return Versioncmp.getRcValue(a, b) return Versioncmp.getRcValue(a, b)
end end
elsif (Versioncmp.isAlpha(big)) elsif (Versioncmp.isAlpha(big))
bigwithoutAlpha = big.gsub(/\.alpha[1-9]*$/i, "") bigwithoutAlpha = big.gsub(/\.alpha.*$/i, "")
bigwithoutAlpha = bigwithoutAlpha.gsub(/\-alpha[1-9]*$/i, "") bigwithoutAlpha = bigwithoutAlpha.gsub(/\-alpha.*$/i, "")
if (Versioncmp.compareString(bigwithoutAlpha, small) == 0) if (Versioncmp.compareString(bigwithoutAlpha, small) == 0)
return Versioncmp.getRcValue(a, b) return Versioncmp.getRcValue(a, b)
end end
elsif (Versioncmp.isPre(big)) elsif (Versioncmp.isPre(big))
bigwithoutPre = big.gsub(/\.pre[1-9]*$/i, "") bigwithoutPre = big.gsub(/\.pre.*$/i, "")
bigwithoutPre = bigwithoutPre.gsub(/\-pre[1-9]*$/i, "") bigwithoutPre = bigwithoutPre.gsub(/\-pre.*$/i, "")
if (Versioncmp.compareString(bigwithoutPre, small) == 0) if (Versioncmp.compareString(bigwithoutPre, small) == 0)
return Versioncmp.getRcValue(a, b) return Versioncmp.getRcValue(a, b)
end end
Expand All @@ -130,15 +130,15 @@ def self.isJbossorg(a)
end end


def self.isBeta(a) def self.isBeta(a)
return a.match(/.*beta[1-9]*$/i) != nil; return a.match(/.*beta.*$/i) != nil;
end end


def self.isAlpha(a) def self.isAlpha(a)
return a.match(/.*alpha[1-9]*$/i) != nil; return a.match(/.*alpha.*$/i) != nil;
end end


def self.isPre(a) def self.isPre(a)
return a.match(/.*pre[1-9]*$/i) != nil; return a.match(/.*pre.*$/i) != nil;
end end


def self.getAPiece(offset, cake) def self.getAPiece(offset, cake)
Expand Down
12 changes: 12 additions & 0 deletions spec/versioncmp_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,10 +42,22 @@
Versioncmp.compare("1.1-alpha1", "1.1").should eql(-1) Versioncmp.compare("1.1-alpha1", "1.1").should eql(-1)
end end


it "smaller alpha-1" do
Versioncmp.compare("1.1-alpha-1", "1.1").should eql(-1)
end

it "smaller alpha" do
Versioncmp.compare("1.1", "1.1-alpha-1").should eql(1)
end

it "smaller beta" do it "smaller beta" do
Versioncmp.compare("3.1-beta1", "3.1").should eql(-1) Versioncmp.compare("3.1-beta1", "3.1").should eql(-1)
end end


it "smaller beta" do
Versioncmp.compare("3.1-beta-1", "3.1").should eql(-1)
end

it "smaller 3.0-rc4-negotiate" do it "smaller 3.0-rc4-negotiate" do
Versioncmp.compare("3.0-rc4-negotiate", "3.0").should eql(-1) Versioncmp.compare("3.0-rc4-negotiate", "3.0").should eql(-1)
end end
Expand Down

0 comments on commit 13341b0

Please sign in to comment.