k_util 0.0.17 → 0.0.19
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/Gemfile +4 -0
- data/lib/k_util/data_helper.rb +10 -29
- data/lib/k_util/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f49e3c0ac1db1cfaf2c310205d474b0e2c24c322fad152a172bed137f7f31d2f
|
4
|
+
data.tar.gz: 2029369204a126de193b01e0219e4b37dc3e0e1745b45cdde01cdc2a159a58cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f0d2550416e6bd606a107b353cc7e2226f59cf22375fac03afac4f59306a2a40622af2a27d0ea0f5fe31577318cd6c39a671b26bd8503d5c8f1c31fe5622fe2
|
7
|
+
data.tar.gz: 63a7cef3672ed4b80a38547272cce5564b68ae795b38d1972ba4d9f2d82ccb16006c96ee58f1ccdf5626f56608e3c45a78609953add05ae32747ba11d7ae3fde
|
data/Gemfile
CHANGED
data/lib/k_util/data_helper.rb
CHANGED
@@ -24,44 +24,25 @@ module KUtil
|
|
24
24
|
#
|
25
25
|
# or an array of deep nested OpenStruct
|
26
26
|
def to_open_struct(data)
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
return OpenStruct.new(data.transform_values { |v| to_open_struct(v) }) if data.is_a?(Hash)
|
28
|
+
return data.map { |o| to_open_struct(o) } if data.is_a?(Array)
|
29
|
+
return to_open_struct(data.to_h) if hash_convertible?(data)
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
when Struct, OpenStruct
|
35
|
-
to_open_struct(data.to_h)
|
36
|
-
|
37
|
-
else
|
38
|
-
# Some primitave type: String, True/False or an ObjectStruct
|
39
|
-
data
|
40
|
-
end
|
31
|
+
# Some primitave type: String, True/False or an ObjectStruct
|
32
|
+
data
|
41
33
|
end
|
42
34
|
|
43
35
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
36
|
+
# Convert data to hash and deal with mixed data types such as Struct and OpenStruct
|
44
37
|
def to_hash(data)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
38
|
+
return {} if data.nil?
|
39
|
+
|
40
|
+
return data.map { |value| hash_convertible?(value) ? to_hash(value) : value } if data.is_a?(Array)
|
49
41
|
|
50
42
|
return to_hash(data.to_h) if !data.is_a?(Hash) && data.respond_to?(:to_h)
|
51
43
|
|
52
44
|
data.each_pair.with_object({}) do |(key, value), hash|
|
53
|
-
|
54
|
-
when OpenStruct, Struct, Hash
|
55
|
-
hash[key] = to_hash(value)
|
56
|
-
when Array
|
57
|
-
# No test yet
|
58
|
-
values = value.map do |v|
|
59
|
-
v.is_a?(OpenStruct) || v.is_a?(Struct) || v.is_a?(Hash) ? to_hash(v) : v
|
60
|
-
end
|
61
|
-
hash[key] = values
|
62
|
-
else
|
63
|
-
hash[key] = value
|
64
|
-
end
|
45
|
+
hash[key] = hash_convertible?(value) ? to_hash(value) : value
|
65
46
|
end
|
66
47
|
end
|
67
48
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
data/lib/k_util/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k_util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " KUtil provides simple utility methods, such as file helpers, data
|
14
14
|
object helpers and more.\n"
|