k_util 0.0.23 → 0.0.24
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 +19 -4
- 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: 8b52770ba6a289d791e99eb4fcf868f87281200424ff7817c07e10b8dd1a4701
|
4
|
+
data.tar.gz: 23ec84b2db507096fd6593360c08570fcb3eac84676edd89f94666b81d8c1a28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78ee597e330cda00891023bb95bbbacfe07178accad429d4724805a7f60f853d0ace04c74ff91c540b3a71a34ef722e3cd1606092c957ac5a368aa7c440a38cd
|
7
|
+
data.tar.gz: 0f7f5913e389eb066f42819040211d68791735a32b9c1af3572fdd08712adcbe4ddfb5c1e3732004be89ef4ba842ef5a339887021426e1e655b6d06ed64135f6
|
data/lib/k_util/data_helper.rb
CHANGED
@@ -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
|
61
|
-
|
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
|
-
|
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)
|
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.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-
|
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"
|