naturalsorter 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +5 -1
- data/lib/naturalsorter/version.rb +1 -1
- data/naturalsorter.gemspec +2 -2
- metadata +7 -12
- data/lib/#natcmp.rb# +0 -76
data/README.markdown
CHANGED
@@ -14,6 +14,10 @@ Because the default sort method does not recognize the numbers in the string. Th
|
|
14
14
|
|
15
15
|
`["init20", "init30", "init200"]`
|
16
16
|
|
17
|
+
## Version Sorting
|
18
|
+
This fork contains some special algorithms to sort version numbers in a natural order. This project is used at <https://www.versioneye.com> to show versions of selected open source projects.
|
19
|
+
|
20
|
+
|
17
21
|
## API
|
18
22
|
|
19
23
|
This GEM has 8 methods
|
@@ -49,7 +53,7 @@ Get newest.
|
|
49
53
|
|
50
54
|
You should add this line to your Gemfile
|
51
55
|
|
52
|
-
`gem 'naturalsorter', '0.3.
|
56
|
+
`gem 'naturalsorter', '0.3.6'`
|
53
57
|
|
54
58
|
and run this command in your app root directory
|
55
59
|
|
data/naturalsorter.gemspec
CHANGED
@@ -5,9 +5,9 @@ require "naturalsorter/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "naturalsorter"
|
7
7
|
s.version = Naturalsorter::VERSION
|
8
|
-
s.authors = ["reiz"]
|
8
|
+
s.authors = ["reiz", "versioneye"]
|
9
9
|
s.email = ["robert.reiz@gmx.com"]
|
10
|
-
s.homepage = "https://github.com/
|
10
|
+
s.homepage = "https://github.com/versioneye/naturalsorter"
|
11
11
|
s.summary = %q{Sorting arrays in natural order}
|
12
12
|
s.description = %q{This GEM is sorting Arrays in a natural order. a2 < a10}
|
13
13
|
|
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: naturalsorter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- reiz
|
9
|
+
- versioneye
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
13
|
+
date: 2012-06-23 00:00:00.000000000Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rspec
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirement: &70123680874700 !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
19
|
requirements:
|
19
20
|
- - ~>
|
@@ -21,12 +22,7 @@ dependencies:
|
|
21
22
|
version: '2.6'
|
22
23
|
type: :development
|
23
24
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '2.6'
|
25
|
+
version_requirements: *70123680874700
|
30
26
|
description: This GEM is sorting Arrays in a natural order. a2 < a10
|
31
27
|
email:
|
32
28
|
- robert.reiz@gmx.com
|
@@ -38,7 +34,6 @@ files:
|
|
38
34
|
- Gemfile
|
39
35
|
- README.markdown
|
40
36
|
- Rakefile
|
41
|
-
- lib/#natcmp.rb#
|
42
37
|
- lib/natcmp.rb
|
43
38
|
- lib/naturalsorter.rb
|
44
39
|
- lib/naturalsorter/version.rb
|
@@ -46,7 +41,7 @@ files:
|
|
46
41
|
- naturalsorter.gemspec
|
47
42
|
- spec/naturalsorter_spec.rb
|
48
43
|
- spec/versioncmp_spec.rb
|
49
|
-
homepage: https://github.com/
|
44
|
+
homepage: https://github.com/versioneye/naturalsorter
|
50
45
|
licenses: []
|
51
46
|
post_install_message:
|
52
47
|
rdoc_options: []
|
@@ -66,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
61
|
version: '0'
|
67
62
|
requirements: []
|
68
63
|
rubyforge_project: naturalsorter
|
69
|
-
rubygems_version: 1.8.
|
64
|
+
rubygems_version: 1.8.17
|
70
65
|
signing_key:
|
71
66
|
specification_version: 3
|
72
67
|
summary: Sorting arrays in natural order
|
data/lib/#natcmp.rb#
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
# natcmp.rb
|
2
|
-
#
|
3
|
-
# Natural order comparison of two strings
|
4
|
-
# e.g. "my_prog_v1.1.0" < "my_prog_v1.2.0" < "my_prog_v1.10.0"
|
5
|
-
# which does not follow alphabetically
|
6
|
-
#
|
7
|
-
# Based on Martin Pool's "Natural Order String Comparison" originally written in C
|
8
|
-
# http://sourcefrog.net/projects/natsort/
|
9
|
-
#
|
10
|
-
# This implementation is Copyright (C) 2003 by Alan Davies
|
11
|
-
# <cs96and_AT_yahoo_DOT_co_DOT_uk>
|
12
|
-
#
|
13
|
-
# This software is provided 'as-is', without any express or implied
|
14
|
-
# warranty. In no event will the authors be held liable for any damages
|
15
|
-
# arising from the use of this software.
|
16
|
-
#
|
17
|
-
# Permission is granted to anyone to use this software for any purpose,
|
18
|
-
# including commercial applications, and to alter it and redistribute it
|
19
|
-
# freely, subject to the following restrictions:
|
20
|
-
#
|
21
|
-
# 1. The origin of this software must not be misrepresented; you must not
|
22
|
-
# claim that you wrote the original software. If you use this software
|
23
|
-
# in a product, an acknowledgment in the product documentation would be
|
24
|
-
# appreciated but is not required.
|
25
|
-
# 2. Altered source versions must be plainly marked as such, and must not be
|
26
|
-
# misrepresented as being the original software.
|
27
|
-
# 3. This notice may not be removed or altered from any source distribution.
|
28
|
-
|
29
|
-
class Natcmp
|
30
|
-
|
31
|
-
# 'Natural order' comparison of two strings
|
32
|
-
def self.natcmp(str1, str2, caseInsensitive=false)
|
33
|
-
str1, str2 = str1.dup, str2.dup
|
34
|
-
compareExpression = /^(\D*)(\d*)(.*)$/
|
35
|
-
|
36
|
-
if caseInsensitive
|
37
|
-
str1.downcase!
|
38
|
-
str2.downcase!
|
39
|
-
end
|
40
|
-
|
41
|
-
# Remove all whitespace
|
42
|
-
str1.gsub!(/\s*/, '')
|
43
|
-
str2.gsub!(/\s*/, '')
|
44
|
-
|
45
|
-
while (str1.length > 0) or (str2.length > 0) do
|
46
|
-
# Extract non-digits, digits and rest of string
|
47
|
-
str1 =~ compareExpression
|
48
|
-
chars1, num1, str1 = $1.dup, $2.dup, $3.dup
|
49
|
-
|
50
|
-
str2 =~ compareExpression
|
51
|
-
chars2, num2, str2 = $1.dup, $2.dup, $3.dup
|
52
|
-
|
53
|
-
# Compare the non-digits
|
54
|
-
case (chars1 <=> chars2)
|
55
|
-
when 0 # Non-digits are the same, compare the digits...
|
56
|
-
# If either number begins with a zero, then compare alphabetically,
|
57
|
-
# otherwise compare numerically
|
58
|
-
if (num1[0] != 48) and (num2[0] != 48)
|
59
|
-
num1, num2 = num1.to_i, num2.to_i
|
60
|
-
end
|
61
|
-
|
62
|
-
case (num1 <=> num2)
|
63
|
-
when -1 then return -1
|
64
|
-
when 1 then return 1
|
65
|
-
end
|
66
|
-
when -1 then return -1
|
67
|
-
when 1 then return 1
|
68
|
-
end # case
|
69
|
-
|
70
|
-
end # while
|
71
|
-
|
72
|
-
# Strings are naturally equal
|
73
|
-
return 0
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|