naturalsorter 0.3.7 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +17 -3
- data/lib/naturalsorter/version.rb +1 -1
- data/lib/naturalsorter.rb +25 -0
- data/spec/naturalsorter_spec.rb +79 -0
- metadata +10 -5
data/README.markdown
CHANGED
@@ -20,8 +20,6 @@ This fork contains some special algorithms to sort version numbers in a natural
|
|
20
20
|
|
21
21
|
## API
|
22
22
|
|
23
|
-
This GEM has 10 methods
|
24
|
-
|
25
23
|
This 2 methods are sorting a simple array of Strings. The name of the methods and the parameters are self explained.
|
26
24
|
|
27
25
|
`Naturalsorter::Sorter.sort(array, caseinsesitive)`
|
@@ -50,6 +48,22 @@ Get the newest version from the both given.
|
|
50
48
|
|
51
49
|
`Naturalsorter::Sorter.get_newest_version(first, second)`
|
52
50
|
|
51
|
+
Is a bigger than b?
|
52
|
+
|
53
|
+
`Naturalsorter::Sorter.bigger?(a, b)`
|
54
|
+
|
55
|
+
Is a bigger than b or equal?
|
56
|
+
|
57
|
+
`Naturalsorter::Sorter.bigger_or_equal?(a, b)`
|
58
|
+
|
59
|
+
Is a smaller than b?
|
60
|
+
|
61
|
+
`Naturalsorter::Sorter.smaller?(a, b)`
|
62
|
+
|
63
|
+
Is a smaller than b or equal?
|
64
|
+
|
65
|
+
`Naturalsorter::Sorter.smaller_or_equal?(a, b)`
|
66
|
+
|
53
67
|
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
68
|
The parameter version would be for example '~>1.1' and the parameter newest_version would be the
|
55
69
|
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.
|
|
62
76
|
|
63
77
|
You should add this line to your Gemfile
|
64
78
|
|
65
|
-
`gem 'naturalsorter', '0.
|
79
|
+
`gem 'naturalsorter', '0.4.7'`
|
66
80
|
|
67
81
|
and run this command in your app root directory
|
68
82
|
|
data/lib/naturalsorter.rb
CHANGED
@@ -90,6 +90,31 @@ module Naturalsorter
|
|
90
90
|
array.last
|
91
91
|
end
|
92
92
|
|
93
|
+
def self.bigger?(a, b)
|
94
|
+
return false if a.eql?(b)
|
95
|
+
newest = Sorter.get_newest_version(a, b)
|
96
|
+
newest.eql?(a)
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.bigger_or_equal?(a, b)
|
100
|
+
return true if a.eql?(b)
|
101
|
+
newest = Sorter.get_newest_version(a, b)
|
102
|
+
newest.eql?(a)
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.smaller?(a, b)
|
106
|
+
return false if a.eql?(b)
|
107
|
+
newest = Sorter.get_newest_version(a, b)
|
108
|
+
newest.eql?(b)
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.smaller_or_equal?(a, b)
|
112
|
+
return true if a.eql?(b)
|
113
|
+
newest = Sorter.get_newest_version(a, b)
|
114
|
+
newest.eql?(b)
|
115
|
+
end
|
116
|
+
|
117
|
+
|
93
118
|
# This is for the GEM notaiton ~>
|
94
119
|
# For example ~>1.1 fits 1.2 and 1.9 and 1.14
|
95
120
|
# But not 2.0
|
data/spec/naturalsorter_spec.rb
CHANGED
@@ -126,8 +126,87 @@ describe Naturalsorter::Sorter do
|
|
126
126
|
end
|
127
127
|
it "returns 1.10" do
|
128
128
|
Naturalsorter::Sorter.get_newest_version("1.10", "1.8").should eql("1.10")
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "bigger?" do
|
134
|
+
|
135
|
+
it "returns true" do
|
136
|
+
Naturalsorter::Sorter.bigger?("1.1", "1.0").should be_true
|
137
|
+
end
|
138
|
+
it "returns true" do
|
139
|
+
Naturalsorter::Sorter.bigger?("2.0", "1.0").should be_true
|
140
|
+
end
|
141
|
+
it "returns true" do
|
142
|
+
Naturalsorter::Sorter.bigger?("2.20", "2.9").should be_true
|
143
|
+
end
|
144
|
+
it "returns false" do
|
145
|
+
Naturalsorter::Sorter.bigger?("2.20", "2.20").should be_false
|
146
|
+
end
|
147
|
+
it "returns false" do
|
148
|
+
Naturalsorter::Sorter.bigger?("2.20", "3.0").should be_false
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "bigger_or_equal?" do
|
154
|
+
|
155
|
+
it "returns true" do
|
156
|
+
Naturalsorter::Sorter.bigger_or_equal?("1.1", "1.0").should be_true
|
157
|
+
end
|
158
|
+
it "returns true" do
|
159
|
+
Naturalsorter::Sorter.bigger_or_equal?("2.0", "1.0").should be_true
|
160
|
+
end
|
161
|
+
it "returns true" do
|
162
|
+
Naturalsorter::Sorter.bigger_or_equal?("2.20", "2.9").should be_true
|
163
|
+
end
|
164
|
+
it "returns true" do
|
165
|
+
Naturalsorter::Sorter.bigger_or_equal?("2.20", "2.20").should be_true
|
166
|
+
end
|
167
|
+
it "returns false" do
|
168
|
+
Naturalsorter::Sorter.bigger_or_equal?("2.20", "3.0").should be_false
|
129
169
|
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "smaller?" do
|
130
174
|
|
175
|
+
it "returns false" do
|
176
|
+
Naturalsorter::Sorter.smaller?("1.1", "1.0").should be_false
|
177
|
+
end
|
178
|
+
it "returns false" do
|
179
|
+
Naturalsorter::Sorter.smaller?("2.0", "1.0").should be_false
|
180
|
+
end
|
181
|
+
it "returns false" do
|
182
|
+
Naturalsorter::Sorter.smaller?("2.20", "2.9").should be_false
|
183
|
+
end
|
184
|
+
it "returns false" do
|
185
|
+
Naturalsorter::Sorter.smaller?("2.20", "2.20").should be_false
|
186
|
+
end
|
187
|
+
it "returns true" do
|
188
|
+
Naturalsorter::Sorter.smaller?("2.20", "3.0").should be_true
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "smaller_or_equal?" do
|
194
|
+
|
195
|
+
it "returns false" do
|
196
|
+
Naturalsorter::Sorter.smaller_or_equal?("1.1", "1.0").should be_false
|
197
|
+
end
|
198
|
+
it "returns false" do
|
199
|
+
Naturalsorter::Sorter.smaller_or_equal?("2.0", "1.0").should be_false
|
200
|
+
end
|
201
|
+
it "returns false" do
|
202
|
+
Naturalsorter::Sorter.smaller_or_equal?("2.20", "2.9").should be_false
|
203
|
+
end
|
204
|
+
it "returns true" do
|
205
|
+
Naturalsorter::Sorter.smaller_or_equal?("2.20", "2.20").should be_true
|
206
|
+
end
|
207
|
+
it "returns true" do
|
208
|
+
Naturalsorter::Sorter.smaller_or_equal?("2.20", "3.0").should be_true
|
209
|
+
end
|
131
210
|
|
132
211
|
end
|
133
212
|
|
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.
|
4
|
+
version: 0.4.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-
|
13
|
+
date: 2012-09-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,7 +22,12 @@ dependencies:
|
|
22
22
|
version: '2.6'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '2.6'
|
26
31
|
description: This GEM is sorting Arrays in a natural order. a2 < a10
|
27
32
|
email:
|
28
33
|
- robert.reiz@gmx.com
|
@@ -61,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
66
|
version: '0'
|
62
67
|
requirements: []
|
63
68
|
rubyforge_project: naturalsorter
|
64
|
-
rubygems_version: 1.8.
|
69
|
+
rubygems_version: 1.8.24
|
65
70
|
signing_key:
|
66
71
|
specification_version: 3
|
67
72
|
summary: Sorting arrays in natural order
|