deep_sort 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/deep_sort.rb +8 -13
- data/lib/deep_sort/array_ext.rb +24 -0
- data/lib/deep_sort/enum_ext.rb +1 -1
- data/lib/deep_sort/extend.rb +2 -2
- data/lib/deep_sort/hash_ext.rb +30 -0
- data/lib/deep_sort/version.rb +1 -1
- metadata +3 -3
- data/lib/deep_sort/array.rb +0 -27
- data/lib/deep_sort/hash.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81628694ecb8fc9d940f5eb522df36d5e7d2404a
|
4
|
+
data.tar.gz: 6b4ac16178c3d8d91adfd72cab177752e3a6d748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56dc5281a15a70d8fefc8731903014eb1c0c30adc58a11c117e7dc9fe8db09b269bb636b92cba1668ed7ee8033f17e9732208cef7f866b6ffadbe48606ab5046
|
7
|
+
data.tar.gz: 6bc041e786bd01a272b86bc3dda4440f9c40d70bcebdec7b151150e8e168984e439b6779280c0207237dcb3de10ec037f7aade977e05c09e9e49bdaca63cd3ba
|
data/lib/deep_sort.rb
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
require 'deep_sort/version'
|
2
|
-
require 'deep_sort/
|
3
|
-
require 'deep_sort/
|
2
|
+
require 'deep_sort/array_ext'
|
3
|
+
require 'deep_sort/hash_ext'
|
4
4
|
|
5
5
|
module DeepSort
|
6
6
|
def deep_sort(obj, options = {})
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
if options[:sort_enum]
|
14
|
-
DeepSort::Array.deep_sort(obj.to_a, options)
|
15
|
-
else
|
16
|
-
obj
|
17
|
-
end
|
7
|
+
if obj.is_a?(Array)
|
8
|
+
DeepSort::ArrayExt.deep_sort(obj, options)
|
9
|
+
elsif obj.is_a?(Hash)
|
10
|
+
DeepSort::HashExt.deep_sort(obj, options)
|
11
|
+
elsif options[:sort_enum] and obj.is_a?(Enumerable)
|
12
|
+
DeepSort::ArrayExt.deep_sort(obj.to_a, options)
|
18
13
|
else
|
19
14
|
obj
|
20
15
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module DeepSort::ArrayExt
|
2
|
+
def deep_sort!(options = {})
|
3
|
+
new_array = self.deep_sort(options)
|
4
|
+
self.replace(new_array)
|
5
|
+
end
|
6
|
+
|
7
|
+
def deep_sort(options)
|
8
|
+
DeepSort::ArrayExt.deep_sort(self, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.deep_sort(array, options = {})
|
12
|
+
array.map {|value|
|
13
|
+
if value.is_a?(Array)
|
14
|
+
DeepSort::ArrayExt.deep_sort(value, options)
|
15
|
+
elsif value.is_a?(Hash)
|
16
|
+
DeepSort::HashExt.deep_sort(value, options)
|
17
|
+
elsif options[:sort_enum] and value.is_a?(Enumerable)
|
18
|
+
DeepSort::ArrayExt.deep_sort(value.to_a, options)
|
19
|
+
else
|
20
|
+
value
|
21
|
+
end
|
22
|
+
}.sort_by(&:to_s)
|
23
|
+
end
|
24
|
+
end
|
data/lib/deep_sort/enum_ext.rb
CHANGED
data/lib/deep_sort/extend.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
module DeepSort::HashExt
|
2
|
+
def deep_sort!(options = {})
|
3
|
+
new_hash = self.deep_sort(options)
|
4
|
+
self.replace(new_hash)
|
5
|
+
end
|
6
|
+
|
7
|
+
def deep_sort(options = {})
|
8
|
+
DeepSort::HashExt.deep_sort(self, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.deep_sort(hash, options = {})
|
12
|
+
new_hash = {}
|
13
|
+
|
14
|
+
hash.keys.sort_by(&:to_s).each do |key|
|
15
|
+
value = hash[key]
|
16
|
+
|
17
|
+
if value.is_a?(Array)
|
18
|
+
value = DeepSort::ArrayExt.deep_sort(value, options)
|
19
|
+
elsif value.is_a?(Hash)
|
20
|
+
value = DeepSort::HashExt.deep_sort(value, options)
|
21
|
+
elsif options[:sort_enum] and value.is_a?(Enumerable)
|
22
|
+
value = DeepSort::ArrayExt.deep_sort(value.to_a, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
new_hash[key] = value
|
26
|
+
end
|
27
|
+
|
28
|
+
new_hash
|
29
|
+
end
|
30
|
+
end
|
data/lib/deep_sort/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_sort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winebarrel
|
@@ -84,10 +84,10 @@ files:
|
|
84
84
|
- bin/setup
|
85
85
|
- deep_sort.gemspec
|
86
86
|
- lib/deep_sort.rb
|
87
|
-
- lib/deep_sort/
|
87
|
+
- lib/deep_sort/array_ext.rb
|
88
88
|
- lib/deep_sort/enum_ext.rb
|
89
89
|
- lib/deep_sort/extend.rb
|
90
|
-
- lib/deep_sort/
|
90
|
+
- lib/deep_sort/hash_ext.rb
|
91
91
|
- lib/deep_sort/version.rb
|
92
92
|
homepage: https://github.com/winebarrel/deep_sort
|
93
93
|
licenses:
|
data/lib/deep_sort/array.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module DeepSort::Array
|
2
|
-
def deep_sort!(options = {})
|
3
|
-
new_array = self.deep_sort(options)
|
4
|
-
self.replace(new_array)
|
5
|
-
end
|
6
|
-
|
7
|
-
def deep_sort(options)
|
8
|
-
DeepSort::Array.deep_sort(self, options)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.deep_sort(array, options = {})
|
12
|
-
array.map {|value|
|
13
|
-
case value
|
14
|
-
when Array, Hash
|
15
|
-
DeepSort.deep_sort(value, options)
|
16
|
-
when Enumerable
|
17
|
-
if options[:sort_enum]
|
18
|
-
DeepSort.deep_sort(value.to_a, options)
|
19
|
-
else
|
20
|
-
value
|
21
|
-
end
|
22
|
-
else
|
23
|
-
value
|
24
|
-
end
|
25
|
-
}.sort_by(&:to_s)
|
26
|
-
end
|
27
|
-
end
|
data/lib/deep_sort/hash.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module DeepSort::Hash
|
2
|
-
def deep_sort!(options = {})
|
3
|
-
new_hash = self.deep_sort(options)
|
4
|
-
self.replace(new_hash)
|
5
|
-
end
|
6
|
-
|
7
|
-
def deep_sort(options = {})
|
8
|
-
DeepSort::Hash.deep_sort(self, options)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.deep_sort(hash, options = {})
|
12
|
-
new_hash = {}
|
13
|
-
|
14
|
-
hash.keys.sort_by(&:to_s).each do |key|
|
15
|
-
value = hash[key]
|
16
|
-
|
17
|
-
case value
|
18
|
-
when Array, Hash
|
19
|
-
value = DeepSort.deep_sort(value, options)
|
20
|
-
when Enumerable
|
21
|
-
if options[:sort_enum]
|
22
|
-
value = DeepSort.deep_sort(value.to_a, options)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
new_hash[key] = value
|
27
|
-
end
|
28
|
-
|
29
|
-
new_hash
|
30
|
-
end
|
31
|
-
end
|