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 CHANGED
@@ -76,7 +76,7 @@ because '~>1.1' doesn't fit anymore the newest version.
76
76
 
77
77
  You should add this line to your Gemfile
78
78
 
79
- `gem 'naturalsorter', '2.0.2'`
79
+ `gem 'naturalsorter', '2.0.3'`
80
80
 
81
81
  and run this command in your app root directory
82
82
 
@@ -1,3 +1,3 @@
1
1
  module Naturalsorter
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
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 nil if (array.nil? || array.empty?)
51
- return nil if array.length == 1
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 nil if (array.nil? || array.empty?)
57
- return nil if array.length == 1
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 nil if (array.nil? || array.empty?)
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 nil if (array.nil? || array.empty?)
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 nil if (array.nil? || array.empty?)
76
- return nil if array.length == 1
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 nil if (array.nil? || array.empty?)
82
- return nil if array.length == 1
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
 
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: 2.0.2
4
+ version: 2.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: