nice_hash 1.17.3 → 1.18.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: 4b492d7a368d6caf79d9e49c2ca75ef4931d1952e91ca822644b4fc46d57cb13
4
- data.tar.gz: e942370a78414668493544e61350c17026d9e294445c3b930aecf6f0a4901aea
3
+ metadata.gz: 5eb4297991e401679fa80b27d5317ad1e7ed2454879b1717c920bd862f7de53f
4
+ data.tar.gz: beb646818a282748bb694d117533ea339d2a702ca7c024746846894e190ab05d
5
5
  SHA512:
6
- metadata.gz: a74d0d1cb4335f55f01c8f726c7bbffb5bc82031f34d66d91aea7a08bf51b245e7a5637a5f7d590423357f375dbcd5ded605623c83619bed23ade7c2c25fc51c
7
- data.tar.gz: 517186ca5314202bf46f5b6747a57e11f796c93ca2d7db07ef45b89d76f2f948d9feb532754ab99e62a9450874228cc79fb969228433250a5284144788f54dee
6
+ metadata.gz: 8332df937c26fc60091db0fb821c4b585029b60976a703d49439adef13f1df03af721b31bb68c1965413ed02bcbbf6ccb005f280ea44731a8b4c5af923610b59
7
+ data.tar.gz: d18ed3d408b262fcc9f982b4cc1bbbaf5795d1f701be3d4aa3ebd80c532156a88a6380e1c9c657d13b050c79ad77275b9a8792d502bdc5e3eb60fc7b306d0a8d
data/README.md CHANGED
@@ -37,6 +37,7 @@ To use nice_hash on Http connections take a look at nice_http gem: https://githu
37
37
  + [Random dates](#random-dates)
38
38
  + [Deep copy of a hash](#deep-copy-of-a-hash)
39
39
  + [Nested deletion](#nested-deletion)
40
+ + [Deep merge of two hashes](#deep-merge-of-two-hashes)
40
41
  + [Boolean class](#boolean-class)
41
42
  * [Other tools integration](#other-tools-integration)
42
43
  + [Tabulo](#tabulo)
@@ -888,6 +889,16 @@ If you want to delete a key on a nested hash you can use `delete_nested` and sup
888
889
  #>{:user=>{:address=>{:country=>"Spain"}, :name=>"Peter", :age=>33}, :customer=>true}
889
890
 
890
891
  ```
892
+ #### Deep merge of two hashes
893
+ If you need to merge multidimensional hashes
894
+
895
+ ```ruby
896
+ my_hash = {one: 1, two: 2, three: {car: 'seat'}}
897
+ other_hash = {one: 11, four: 44, three: {car: 'ferrari', model: 'unknown'}}
898
+ p my_hash.nice_merge(other_hash)
899
+ #>{:one=>11, :two=>2, :three=>{:car=>"ferrari", :model=>"unknown"}, :four=>44}
900
+ ```
901
+
891
902
 
892
903
  #### Boolean class
893
904
  We added the possibility to check if a value is boolean or not since in Ruby doesn't exist, just TrueClass and FalseClass
@@ -288,9 +288,26 @@ class Hash
288
288
  NiceHash.nice_filter(self, keys)
289
289
  end
290
290
 
291
+ ###########################################################################
292
+ # Merging multi-dimensional hashes
293
+ ###########################################################################
294
+ def nice_merge(hash = nil)
295
+ return self unless hash.is_a?(Hash)
296
+ base = self
297
+ hash.each do |key, v|
298
+ if base[key].is_a?(Hash) && hash[key].is_a?(Hash)
299
+ base[key].nice_merge(hash[key])
300
+ else
301
+ base[key]= hash[key]
302
+ end
303
+ end
304
+ base
305
+ end
306
+
291
307
  alias gen generate
292
308
  alias val validate
293
309
  alias patterns pattern_fields
310
+ alias nice_copy deep_copy
294
311
  end
295
312
 
296
313
  class Object
@@ -34,6 +34,7 @@ class NiceHash
34
34
  end
35
35
 
36
36
  end
37
+
37
38
  hash_array.each do |k, v|
38
39
  #for the case of using same_values: [:pwd1, :pwd2] => :'10:N' and supply hash_values: pwd1: 'a', pwd2: 'b'
39
40
  #instead of [:pwd1,:pwd2]=>'a'
@@ -69,8 +70,8 @@ class NiceHash
69
70
  hash_values.each do |kk,vv|
70
71
  if kk.to_s.match?(/^#{k}\./)
71
72
  kk = kk.to_s.gsub(/^#{k}\./, '').to_sym
72
- new_hash_values[kk] = vv
73
73
  end
74
+ new_hash_values[kk] = vv
74
75
  end
75
76
  hashv[k] = NiceHash.set_values(v, new_hash_values)
76
77
  else
@@ -81,9 +82,11 @@ class NiceHash
81
82
  end
82
83
  end
83
84
  end
85
+
84
86
  hash_values.each do |k, v|
85
87
  hashv = NiceHash.set_nested(hashv, k, v, true) if k.is_a?(Hash)
86
88
  end
89
+
87
90
  return hashv
88
91
  elsif hash_array.is_a?(Array) and hash_array.size > 0
89
92
  hashv = Array.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nice_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.3
4
+ version: 1.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-20 00:00:00.000000000 Z
11
+ date: 2023-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string_pattern
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  requirements: []
104
- rubygems_version: 3.2.15
104
+ rubygems_version: 3.4.3
105
105
  signing_key:
106
106
  specification_version: 4
107
107
  summary: NiceHash creates hashes following certain patterns so your testing will be