naturalsorter 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -20,40 +20,49 @@ This fork contains some special algorithms to sort version numbers in a natural
20
20
 
21
21
  ## API
22
22
 
23
- This GEM has 8 methods
23
+ This GEM has 10 methods
24
+
25
+ This 2 methods are sorting a simple array of Strings. The name of the methods and the parameters are self explained.
24
26
 
25
27
  `Naturalsorter::Sorter.sort(array, caseinsesitive)`
26
28
 
27
29
  `Naturalsorter::Sorter.sort_desc(array, caseinsesitive)`
28
30
 
29
- 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.
31
+ 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.
30
32
 
31
33
  `Naturalsorter::Sorter.sort_by_method(array, method, caseinsesitive)`
32
34
 
33
35
  `Naturalsorter::Sorter.sort_by_method_desc(array, method, caseinsesitive)`
34
36
 
35
- This methods are based on a different algo. spezially optimizied for sorting version strings.
37
+ This methods are based on a different algo. Spezially optimizied for sorting version strings.
36
38
 
37
39
  `Naturalsorter::Sorter.sort_version(array)`
38
40
 
39
41
  `Naturalsorter::Sorter.sort_version_desc(array)`
40
42
 
41
- This here is again for an array with objects.
43
+ This here is again for an array with objects. Spezially optimizied for sorting version strings.
42
44
 
43
45
  `Naturalsorter::Sorter.sort_version_by_method(array, method)`
44
46
 
45
47
  `Naturalsorter::Sorter.sort_version_by_method_desc(array)`
46
48
 
47
- Get newest.
49
+ Get the newest version from the both given.
48
50
 
49
51
  `Naturalsorter::Sorter.get_newest_version(first, second)`
50
52
 
53
+ This is for the Ruby GEM notaiton '~>'. For example '~>1.1' fits '1.2' and '1.9' and '1.14'. But not 2.0.
54
+ The parameter version would be for example '~>1.1' and the parameter newest_version would be the
55
+ current newest version of the GEM, for example "2.0". The method will return false in this case
56
+ because '~>1.1' doesn't fit anymore the newest version.
57
+
58
+ `Naturalsorter::Sorter.is_version_current?(version, newest_version)`
59
+
51
60
 
52
61
  ## Installation
53
62
 
54
63
  You should add this line to your Gemfile
55
64
 
56
- `gem 'naturalsorter', '0.3.6'`
65
+ `gem 'naturalsorter', '0.3.7'`
57
66
 
58
67
  and run this command in your app root directory
59
68
 
data/lib/naturalsorter.rb CHANGED
@@ -90,13 +90,17 @@ module Naturalsorter
90
90
  array.last
91
91
  end
92
92
 
93
- def self.is_version_current?(version, current_version)
93
+ # This is for the GEM notaiton ~>
94
+ # For example ~>1.1 fits 1.2 and 1.9 and 1.14
95
+ # But not 2.0
96
+ def self.is_version_current?(version, newest_version)
94
97
  version = version.gsub("~>", "")
98
+ version = version.gsub(" " , "")
95
99
  versions = version.split(".")
96
- currents = current_version.split(".")
100
+ newests = newest_version.split(".")
97
101
  min_length = versions.size
98
- if currents.size < min_length
99
- min_length = currents.size
102
+ if newests.size < min_length
103
+ min_length = newests.size
100
104
  end
101
105
  min_length = min_length - 2
102
106
  if min_length < 0
@@ -104,14 +108,14 @@ module Naturalsorter
104
108
  end
105
109
  (0..min_length).each do |z|
106
110
  ver = versions[z]
107
- cur = currents[z]
111
+ cur = newests[z]
108
112
  if (cur > ver)
109
113
  return false
110
114
  end
111
115
  end
112
- if currents.size < versions.size
116
+ if newests.size < versions.size
113
117
  ver = versions[min_length + 1]
114
- cur = currents[min_length + 1]
118
+ cur = newests[min_length + 1]
115
119
  if cur > ver
116
120
  return false
117
121
  end
@@ -1,3 +1,3 @@
1
1
  module Naturalsorter
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
@@ -87,6 +87,12 @@ describe Naturalsorter::Sorter do
87
87
  it "returns true" do
88
88
  Naturalsorter::Sorter.is_version_current?("1.1.1", "1.1.9").should be_true
89
89
  end
90
+ it "returns true" do
91
+ Naturalsorter::Sorter.is_version_current?("1.1.1", "1.1.2").should be_true
92
+ end
93
+ it "returns true" do
94
+ Naturalsorter::Sorter.is_version_current?("1.1.1", "1.1.12").should be_true
95
+ end
90
96
  it "returns false" do
91
97
  Naturalsorter::Sorter.is_version_current?("1.1.1", "1.2.0").should be_false
92
98
  end
@@ -99,6 +105,9 @@ describe Naturalsorter::Sorter do
99
105
  it "returns false" do
100
106
  Naturalsorter::Sorter.is_version_current?("1.1.1", "2").should be_false
101
107
  end
108
+ it "returns false" do
109
+ Naturalsorter::Sorter.is_version_current?("1.1", "2.0").should be_false
110
+ end
102
111
  end
103
112
 
104
113
  describe "get_newest_version" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: naturalsorter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-23 00:00:00.000000000Z
13
+ date: 2012-06-24 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &70123680874700 !ruby/object:Gem::Requirement
17
+ requirement: &70249509911580 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: '2.6'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70123680874700
25
+ version_requirements: *70249509911580
26
26
  description: This GEM is sorting Arrays in a natural order. a2 < a10
27
27
  email:
28
28
  - robert.reiz@gmx.com