k_util 0.0.19 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/k_util/data_helper.rb +14 -10
- data/lib/k_util/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 615b0deb70283841ac540e1af6a4153dcf7fdb6b1eb85f4710119edd7c662507
|
4
|
+
data.tar.gz: 0cf049101ab9e7ea4e76943c2e19e69a550d4dca78f31b2a70e6e51f6ca13a5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d85601784381afbea1385b067cd646ddb72675a463638b2b4b611fff3657d1924ca4dba2f0ede9fa1bd17090481c54814a31d24f92190a47dfa735512677615
|
7
|
+
data.tar.gz: 0a15d56a6099b870971367b360fe6a2780c30fcedc1b9b759c6e2cccfe698a4386d2f85af143057c3f4f7df7f3b918ca4b73ba46241f2b6503eeb58756b3e0d8
|
data/lib/k_util/data_helper.rb
CHANGED
@@ -35,6 +35,7 @@ module KUtil
|
|
35
35
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
36
36
|
# Convert data to hash and deal with mixed data types such as Struct and OpenStruct
|
37
37
|
def to_hash(data)
|
38
|
+
# This nil check is only for the root object
|
38
39
|
return {} if data.nil?
|
39
40
|
|
40
41
|
return data.map { |value| hash_convertible?(value) ? to_hash(value) : value } if data.is_a?(Array)
|
@@ -53,19 +54,22 @@ module KUtil
|
|
53
54
|
value.is_a?(Symbol) ? value.to_s : value
|
54
55
|
end
|
55
56
|
|
56
|
-
#
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
# end
|
57
|
+
# Is the value a basic (aka primitive) type
|
58
|
+
def basic_type?(value)
|
59
|
+
value.is_a?(String) ||
|
60
|
+
value.is_a?(Symbol) ||
|
61
|
+
value.is_a?(FalseClass) ||
|
62
|
+
value.is_a?(TrueClass) ||
|
63
|
+
value.is_a?(Integer) ||
|
64
|
+
value.is_a?(Float)
|
65
|
+
end
|
66
66
|
|
67
67
|
# Is the value a complex container type, but not a regular class.
|
68
68
|
def hash_convertible?(value)
|
69
|
+
# Nil is a special case, it responds to :to_h but generally
|
70
|
+
# you only want to convert nil to {} in specific scenarios
|
71
|
+
return false if value.nil?
|
72
|
+
|
69
73
|
value.is_a?(Array) ||
|
70
74
|
value.is_a?(Hash) ||
|
71
75
|
value.is_a?(Struct) ||
|
data/lib/k_util/version.rb
CHANGED