Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding more docu

  • Loading branch information...
commit 17ff1096eb6f0e914db5e48e10d01d29efc3ece7 1 parent 0e91e24
@reiz reiz authored
View
21 README.markdown
@@ -20,40 +20,49 @@ This fork contains some special algorithms to sort version numbers in a natural
## API
-This GEM has 8 methods
+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)`
`Naturalsorter::Sorter.sort_desc(array, caseinsesitive)`
-And this here for more advanced sorting. Where you can put in a array of objects and the method which should called on every object for comparison.
+And this here is for more advanced sorting. Where you can put in a array of objects and the method which should called on every object for comparison.
`Naturalsorter::Sorter.sort_by_method(array, method, caseinsesitive)`
`Naturalsorter::Sorter.sort_by_method_desc(array, method, caseinsesitive)`
-This methods are based on a different algo. spezially optimizied for sorting version strings.
+This methods are based on a different algo. Spezially optimizied for sorting version strings.
`Naturalsorter::Sorter.sort_version(array)`
`Naturalsorter::Sorter.sort_version_desc(array)`
-This here is again for an array with objects.
+This here is again for an array with objects. Spezially optimizied for sorting version strings.
`Naturalsorter::Sorter.sort_version_by_method(array, method)`
`Naturalsorter::Sorter.sort_version_by_method_desc(array)`
-Get newest.
+Get the newest version from the both given.
`Naturalsorter::Sorter.get_newest_version(first, second)`
+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
+because '~>1.1' doesn't fit anymore the newest version.
+
+`Naturalsorter::Sorter.is_version_current?(version, newest_version)`
+
## Installation
You should add this line to your Gemfile
-`gem 'naturalsorter', '0.3.6'`
+`gem 'naturalsorter', '0.3.7'`
and run this command in your app root directory
View
18 lib/naturalsorter.rb
@@ -90,13 +90,17 @@ def self.get_newest_version(first, second)
array.last
end
- def self.is_version_current?(version, current_version)
+ # This is for the GEM notaiton ~>
+ # For example ~>1.1 fits 1.2 and 1.9 and 1.14
+ # But not 2.0
+ def self.is_version_current?(version, newest_version)
version = version.gsub("~>", "")
+ version = version.gsub(" " , "")
versions = version.split(".")
- currents = current_version.split(".")
+ newests = newest_version.split(".")
min_length = versions.size
- if currents.size < min_length
- min_length = currents.size
+ if newests.size < min_length
+ min_length = newests.size
end
min_length = min_length - 2
if min_length < 0
@@ -104,14 +108,14 @@ def self.is_version_current?(version, current_version)
end
(0..min_length).each do |z|
ver = versions[z]
- cur = currents[z]
+ cur = newests[z]
if (cur > ver)
return false
end
end
- if currents.size < versions.size
+ if newests.size < versions.size
ver = versions[min_length + 1]
- cur = currents[min_length + 1]
+ cur = newests[min_length + 1]
if cur > ver
return false
end
View
2  lib/naturalsorter/version.rb
@@ -1,3 +1,3 @@
module Naturalsorter
- VERSION = "0.3.6"
+ VERSION = "0.3.7"
end
View
9 spec/naturalsorter_spec.rb
@@ -87,6 +87,12 @@
it "returns true" do
Naturalsorter::Sorter.is_version_current?("1.1.1", "1.1.9").should be_true
end
+ it "returns true" do
+ Naturalsorter::Sorter.is_version_current?("1.1.1", "1.1.2").should be_true
+ end
+ it "returns true" do
+ Naturalsorter::Sorter.is_version_current?("1.1.1", "1.1.12").should be_true
+ end
it "returns false" do
Naturalsorter::Sorter.is_version_current?("1.1.1", "1.2.0").should be_false
end
@@ -99,6 +105,9 @@
it "returns false" do
Naturalsorter::Sorter.is_version_current?("1.1.1", "2").should be_false
end
+ it "returns false" do
+ Naturalsorter::Sorter.is_version_current?("1.1", "2.0").should be_false
+ end
end
describe "get_newest_version" do
Please sign in to comment.
Something went wrong with that request. Please try again.