naturalsorter 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/lib/naturalsorter/version.rb +1 -1
- data/lib/naturalsorter.rb +12 -16
- metadata +1 -1
data/README.markdown
CHANGED
data/lib/naturalsorter.rb
CHANGED
@@ -31,55 +31,51 @@ module Naturalsorter
|
|
31
31
|
|
32
32
|
# 'Natural order' sort for an simple string array
|
33
33
|
def self.sort(array, caseinsesitive)
|
34
|
-
if (array.nil? || array.empty?)
|
35
|
-
return nil
|
36
|
-
end
|
34
|
+
return array if (array.nil? || array.empty?)
|
37
35
|
array.sort { |a,b| Natcmp.natcmp(a, b, caseinsesitive) }
|
38
36
|
end
|
39
37
|
|
40
38
|
def self.sort_desc(array, caseinsesitive)
|
41
|
-
if (array.nil? || array.empty?)
|
42
|
-
return nil
|
43
|
-
end
|
39
|
+
return array if (array.nil? || array.empty?)
|
44
40
|
array.sort { |a, b| Natcmp.natcmp(b, a, caseinsesitive) }
|
45
41
|
end
|
46
42
|
|
47
43
|
|
48
44
|
# 'Natural order' sort for an array of objects.
|
49
45
|
def self.sort_by_method(array, method, caseinsesitive)
|
50
|
-
return
|
51
|
-
return
|
46
|
+
return array if (array.nil? || array.empty?)
|
47
|
+
return array if array.length == 1
|
52
48
|
array.sort { |a,b| Natcmp.natcmp( a.send(method), b.send(method), caseinsesitive) }
|
53
49
|
end
|
54
50
|
|
55
51
|
def self.sort_by_method_desc(array, method, caseinsesitive)
|
56
|
-
return
|
57
|
-
return
|
52
|
+
return array if (array.nil? || array.empty?)
|
53
|
+
return array if array.length == 1
|
58
54
|
array.sort { |a, b| Natcmp.natcmp(b.send(method), a.send(method), caseinsesitive) }
|
59
55
|
end
|
60
56
|
|
61
57
|
|
62
58
|
def self.sort_version(array)
|
63
|
-
return
|
59
|
+
return array if (array.nil? || array.empty?)
|
64
60
|
array.sort { |a,b| Versioncmp.compare( a, b ) }
|
65
61
|
end
|
66
62
|
|
67
63
|
def self.sort_version_desc(array)
|
68
|
-
return
|
64
|
+
return array if (array.nil? || array.empty?)
|
69
65
|
array.sort { |a,b| Versioncmp.compare( b, a ) }
|
70
66
|
end
|
71
67
|
|
72
68
|
|
73
69
|
|
74
70
|
def self.sort_version_by_method(array, method)
|
75
|
-
return
|
76
|
-
return
|
71
|
+
return array if (array.nil? || array.empty?)
|
72
|
+
return array if array.length == 1
|
77
73
|
array.sort { |a,b| Versioncmp.compare(a.send(method), b.send(method)) }
|
78
74
|
end
|
79
75
|
|
80
76
|
def self.sort_version_by_method_desc(array, method)
|
81
|
-
return
|
82
|
-
return
|
77
|
+
return array if (array.nil? || array.empty?)
|
78
|
+
return array if array.length == 1
|
83
79
|
array.sort { |a,b| Versioncmp.compare(b.send(method), a.send(method)) }
|
84
80
|
end
|
85
81
|
|