Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding methods for bigger, smaller, smaller_than and bigger_than

  • Loading branch information...
commit 558c276d06721c94ffaf8061089d3439259a6149 1 parent 17ff109
@reiz reiz authored
View
20 README.markdown
@@ -20,8 +20,6 @@ This fork contains some special algorithms to sort version numbers in a natural
## API
-This GEM has 10 methods
-
This 2 methods are sorting a simple array of Strings. The name of the methods and the parameters are self explained.
`Naturalsorter::Sorter.sort(array, caseinsesitive)`
@@ -50,6 +48,22 @@ Get the newest version from the both given.
`Naturalsorter::Sorter.get_newest_version(first, second)`
+Is a bigger than b?
+
+`Naturalsorter::Sorter.bigger?(a, b)`
+
+Is a bigger than b or equal?
+
+`Naturalsorter::Sorter.bigger_or_equal?(a, b)`
+
+Is a smaller than b?
+
+`Naturalsorter::Sorter.smaller?(a, b)`
+
+Is a smaller than b or equal?
+
+`Naturalsorter::Sorter.smaller_or_equal?(a, b)`
+
This is for the Ruby GEM notaiton '~>'. For example '~>1.1' fits '1.2' and '1.9' and '1.14'. But not 2.0.
The parameter version would be for example '~>1.1' and the parameter newest_version would be the
current newest version of the GEM, for example "2.0". The method will return false in this case
@@ -62,7 +76,7 @@ because '~>1.1' doesn't fit anymore the newest version.
You should add this line to your Gemfile
-`gem 'naturalsorter', '0.3.7'`
+`gem 'naturalsorter', '0.4.7'`
and run this command in your app root directory
View
25 lib/naturalsorter.rb
@@ -90,6 +90,31 @@ def self.get_newest_version(first, second)
array.last
end
+ def self.bigger?(a, b)
+ return false if a.eql?(b)
+ newest = Sorter.get_newest_version(a, b)
+ newest.eql?(a)
+ end
+
+ def self.bigger_or_equal?(a, b)
+ return true if a.eql?(b)
+ newest = Sorter.get_newest_version(a, b)
+ newest.eql?(a)
+ end
+
+ def self.smaller?(a, b)
+ return false if a.eql?(b)
+ newest = Sorter.get_newest_version(a, b)
+ newest.eql?(b)
+ end
+
+ def self.smaller_or_equal?(a, b)
+ return true if a.eql?(b)
+ newest = Sorter.get_newest_version(a, b)
+ newest.eql?(b)
+ end
+
+
# This is for the GEM notaiton ~>
# For example ~>1.1 fits 1.2 and 1.9 and 1.14
# But not 2.0
View
2  lib/naturalsorter/version.rb
@@ -1,3 +1,3 @@
module Naturalsorter
- VERSION = "0.3.7"
+ VERSION = "0.4.7"
end
View
79 spec/naturalsorter_spec.rb
@@ -126,8 +126,87 @@
end
it "returns 1.10" do
Naturalsorter::Sorter.get_newest_version("1.10", "1.8").should eql("1.10")
+ end
+
+ end
+
+ describe "bigger?" do
+
+ it "returns true" do
+ Naturalsorter::Sorter.bigger?("1.1", "1.0").should be_true
+ end
+ it "returns true" do
+ Naturalsorter::Sorter.bigger?("2.0", "1.0").should be_true
+ end
+ it "returns true" do
+ Naturalsorter::Sorter.bigger?("2.20", "2.9").should be_true
+ end
+ it "returns false" do
+ Naturalsorter::Sorter.bigger?("2.20", "2.20").should be_false
+ end
+ it "returns false" do
+ Naturalsorter::Sorter.bigger?("2.20", "3.0").should be_false
+ end
+
+ end
+
+ describe "bigger_or_equal?" do
+
+ it "returns true" do
+ Naturalsorter::Sorter.bigger_or_equal?("1.1", "1.0").should be_true
+ end
+ it "returns true" do
+ Naturalsorter::Sorter.bigger_or_equal?("2.0", "1.0").should be_true
+ end
+ it "returns true" do
+ Naturalsorter::Sorter.bigger_or_equal?("2.20", "2.9").should be_true
+ end
+ it "returns true" do
+ Naturalsorter::Sorter.bigger_or_equal?("2.20", "2.20").should be_true
+ end
+ it "returns false" do
+ Naturalsorter::Sorter.bigger_or_equal?("2.20", "3.0").should be_false
end
+
+ end
+
+ describe "smaller?" do
+ it "returns false" do
+ Naturalsorter::Sorter.smaller?("1.1", "1.0").should be_false
+ end
+ it "returns false" do
+ Naturalsorter::Sorter.smaller?("2.0", "1.0").should be_false
+ end
+ it "returns false" do
+ Naturalsorter::Sorter.smaller?("2.20", "2.9").should be_false
+ end
+ it "returns false" do
+ Naturalsorter::Sorter.smaller?("2.20", "2.20").should be_false
+ end
+ it "returns true" do
+ Naturalsorter::Sorter.smaller?("2.20", "3.0").should be_true
+ end
+
+ end
+
+ describe "smaller_or_equal?" do
+
+ it "returns false" do
+ Naturalsorter::Sorter.smaller_or_equal?("1.1", "1.0").should be_false
+ end
+ it "returns false" do
+ Naturalsorter::Sorter.smaller_or_equal?("2.0", "1.0").should be_false
+ end
+ it "returns false" do
+ Naturalsorter::Sorter.smaller_or_equal?("2.20", "2.9").should be_false
+ end
+ it "returns true" do
+ Naturalsorter::Sorter.smaller_or_equal?("2.20", "2.20").should be_true
+ end
+ it "returns true" do
+ Naturalsorter::Sorter.smaller_or_equal?("2.20", "3.0").should be_true
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.