k_util 0.0.23 → 0.0.24

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: 1cc4532082b846b6644fab95de5f16943585311d07b7dab25247418e62960e93
4
- data.tar.gz: 59025e0e712857e698aa30242be084d0a85ab3020cea20a6f7fd49c153a2537e
3
+ metadata.gz: 8b52770ba6a289d791e99eb4fcf868f87281200424ff7817c07e10b8dd1a4701
4
+ data.tar.gz: 23ec84b2db507096fd6593360c08570fcb3eac84676edd89f94666b81d8c1a28
5
5
  SHA512:
6
- metadata.gz: 90e2cdc37229d364f87dcb196a6366d1cf86e62e30634b1fff4fcc6ee5dac941396a145a052337c2b1d56a85180640c69b84c18f80c932ec667047163106cc3a
7
- data.tar.gz: e839e60ad5abb4b00e0e46f66172255fb20976e4de99b44d80fc7d64d53fa798b5c73d82de9d6d6c9228173c19d43408c2ac81dfda91d6f471d597c67c9d30b6
6
+ metadata.gz: 78ee597e330cda00891023bb95bbbacfe07178accad429d4724805a7f60f853d0ace04c74ff91c540b3a71a34ef722e3cd1606092c957ac5a368aa7c440a38cd
7
+ data.tar.gz: 0f7f5913e389eb066f42819040211d68791735a32b9c1af3572fdd08712adcbe4ddfb5c1e3732004be89ef4ba842ef5a339887021426e1e655b6d06ed64135f6
@@ -6,6 +6,7 @@ module KUtil
6
6
  class DataHelper
7
7
  # Convert JSON string into to_open_struct but designed to work with a JSON string
8
8
  #
9
+ # KUtil.data.parse_json(json, as: :symbolize_keys)
9
10
  # https://docs.ruby-lang.org/en/master/JSON.html
10
11
  # rubocop:disable Naming/MethodParameterName
11
12
  def parse_json(json, as: :hash)
@@ -14,7 +15,7 @@ module KUtil
14
15
  case as
15
16
  when :hash
16
17
  JSON.parse(json)
17
- when :hash_symbolized
18
+ when :hash_symbolized, :symbolize_names, :symbolize_keys
18
19
  JSON.parse(json, symbolize_names: true)
19
20
  when :open_struct
20
21
  JSON.parse(json, object_class: OpenStruct)
@@ -57,10 +58,24 @@ module KUtil
57
58
  value.is_a?(Symbol) ? value.to_s : value
58
59
  end
59
60
 
60
- def symbolize_names(hash)
61
- hash.transform_keys(&:to_sym)
61
+ def deep_symbolize_keys(input)
62
+ return input if input.nil?
63
+
64
+ return input unless input.is_a?(Hash)
65
+
66
+ input.each_with_object({}) do |key_value, new_hash|
67
+ key, value = key_value
68
+ value = deep_symbolize_keys(value) if value.is_a?(Hash)
69
+ value = value.map { |v| deep_symbolize_keys(v) } if value.is_a?(Array)
70
+ new_hash[key.to_sym] = value
71
+ end
62
72
  end
63
- alias symbolize_keys symbolize_names
73
+
74
+ # def deep_symbolize_keys(hash)
75
+ # return hash if hash.nil?
76
+
77
+ # hash.transform_keys(&:to_sym)
78
+ # end
64
79
 
65
80
  # Is the value a basic (aka primitive) type
66
81
  def basic_type?(value)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KUtil
4
- VERSION = '0.0.23'
4
+ VERSION = '0.0.24'
5
5
  end
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.23
4
+ version: 0.0.24
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-08-27 00:00:00.000000000 Z
11
+ date: 2021-08-28 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"