k_util 0.0.19 → 0.0.22

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f49e3c0ac1db1cfaf2c310205d474b0e2c24c322fad152a172bed137f7f31d2f
4
- data.tar.gz: 2029369204a126de193b01e0219e4b37dc3e0e1745b45cdde01cdc2a159a58cf
3
+ metadata.gz: 615b0deb70283841ac540e1af6a4153dcf7fdb6b1eb85f4710119edd7c662507
4
+ data.tar.gz: 0cf049101ab9e7ea4e76943c2e19e69a550d4dca78f31b2a70e6e51f6ca13a5c
5
5
  SHA512:
6
- metadata.gz: 3f0d2550416e6bd606a107b353cc7e2226f59cf22375fac03afac4f59306a2a40622af2a27d0ea0f5fe31577318cd6c39a671b26bd8503d5c8f1c31fe5622fe2
7
- data.tar.gz: 63a7cef3672ed4b80a38547272cce5564b68ae795b38d1972ba4d9f2d82ccb16006c96ee58f1ccdf5626f56608e3c45a78609953add05ae32747ba11d7ae3fde
6
+ metadata.gz: 5d85601784381afbea1385b067cd646ddb72675a463638b2b4b611fff3657d1924ca4dba2f0ede9fa1bd17090481c54814a31d24f92190a47dfa735512677615
7
+ data.tar.gz: 0a15d56a6099b870971367b360fe6a2780c30fcedc1b9b759c6e2cccfe698a4386d2f85af143057c3f4f7df7f3b918ca4b73ba46241f2b6503eeb58756b3e0d8
@@ -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
- # Add if needed
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
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) ||
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KUtil
4
- VERSION = '0.0.19'
4
+ VERSION = '0.0.22'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys