hash_to_struct 0.1.0 → 0.1.1

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: 8606f1e55e6fbabe1ccb0d02f70688025b87aed05490ba221896605c92d31402
4
- data.tar.gz: 5d51c847d87d7c96dfd8938301c68effa74e51bc450094447c35b8beddab8096
3
+ metadata.gz: f85aaeb54564d1fb5350a2545cd5117b74ec826c8119cb81981875a12e96f8e8
4
+ data.tar.gz: b58404ae47204c1d6ba18da843c6526b2fd90d678e8aa668fd125febfeec7168
5
5
  SHA512:
6
- metadata.gz: 61ffa8d5725f6552e0b35174d69d9e566693c736c1e695b682643613ca3a0a0b8c4976f2d54e54c043c42a9e0993855f2155aff7a077e6f05ac99f051e72d2dc
7
- data.tar.gz: 9c8bc999bc6e71ca6b76ccdf0f0093aaf75301a89507b1da41f10e4216dadae9e32eb6c23113848888af25741457ff4eac2d50fb0abaa242a192017054c89342
6
+ metadata.gz: c84576fc423c375963361beb0ae9c2b704a926084192f76ec27ec4b95884119e45edefdf056fafbd0a120766420043feee91d2361dca5c0b1abf990119d7c200
7
+ data.tar.gz: ca81da797059808926fbe6b44d985c500c8b7df7bcf79e6dd98aa102d18750120f0e85c6c3dd7d26cd49a811dce7ccad3cf7ce3531a870e1db02c67011cc5d92
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1 (2022-01-21)
4
+
5
+ ### Bug Fixes
6
+
7
+ * skip non Hash members of included arrays
8
+
3
9
  ## 0.1.0 (2022-01-17)
@@ -25,11 +25,11 @@ module HashToStruct
25
25
 
26
26
  def to_struct(hash)
27
27
  h = hash.each_key.each_with_object({}) do |key, h|
28
- create_new = -> (hv) { self.class.new(hv, **@options) }
28
+ create_new = -> (v) { is_hash?(v) ? self.class.new(v, **@options) : v}
29
29
  h[key] = case
30
- when hash[key].class == Hash
30
+ when is_hash?(hash[key])
31
31
  create_new.call(hash[key])
32
- when @options[:including_arrays] && hash[key].class == Array
32
+ when @options[:including_arrays] && is_array?(hash[key])
33
33
  hash[key].map(&create_new)
34
34
  else
35
35
  hash[key]
@@ -43,12 +43,21 @@ module HashToStruct
43
43
  h.keys.each do |key|
44
44
  h[key] = case
45
45
  when h[key].is_a?(self.class) then h[key].to_h
46
- when h[key].class == Array then h[key].map(&:to_h)
46
+ when is_array?(h[key])
47
+ h[key].map { |v| v.is_a?(self.class) ? v.to_h : v }
47
48
  else
48
49
  h[key]
49
50
  end
50
51
  end
51
52
  end
52
53
  end
54
+
55
+ def is_hash?(val)
56
+ val.class == Hash
57
+ end
58
+
59
+ def is_array?(val)
60
+ val.class == Array
61
+ end
53
62
  end
54
63
  end
@@ -1,3 +1,3 @@
1
1
  module HashToStruct
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_to_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Bohush
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-17 00:00:00.000000000 Z
11
+ date: 2022-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake