nice_hash 1.12.13 → 1.12.14

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nice_hash.rb +46 -13
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 160dc4a4a31b1c19945bd9abdcd63cc533d2c43507e2203938a6c669b108d06d
4
- data.tar.gz: 1ab71eed50c782832be864d79edbdc8f88021c4b741917a874cbece6c041c1ca
3
+ metadata.gz: c04f2f984651321da92e9adab8820cb92334b4e719d800830f0d9a6cee052238
4
+ data.tar.gz: 9c9dff7d8107996236770e99aeaf8bd7e995a76738bfa2cd3b6e3a126ac23bb6
5
5
  SHA512:
6
- metadata.gz: b6468de26ff322ac3015c251439bc4199a69054db6d78c1cd6d167e17c48b39c11372449838ea1924748c48dd05779c224f250cdc1def7b34cbb12a56298d2a2
7
- data.tar.gz: 005dc902f3fd66ecd70a47cdabb9146e861f9ff758a7467b615f4fd0feee3d174804fc2b0d0ac3ead8590bb824b10239eaa1b10cb4daa64129188ae1ba7f6909
6
+ metadata.gz: d6059cb29c2f15b07bd83f50dd17959461ab3e208de0d196c67bacabd70d92ba29b12017f640977dea5819e8b2ebf72899fb4098a965372e84644441021d460e
7
+ data.tar.gz: '09f8201012b7715473c62715eca70b96161c0e30c6b9ce403b5ab6c861567ac1bb6d095e6c6ac6317510f3eb1e427d47f1d22a59c67de720dfd6480ce3dbda76'
@@ -551,6 +551,10 @@ class NiceHash
551
551
  return { error: :error }
552
552
  end
553
553
  values = values_hash_to_validate
554
+ if pattern_hash.keys.size == get_all_keys(pattern_hash).size and values.keys.size != get_all_keys(values)
555
+ # all patterns on patterns_hash are described on first level, so no same structure than values
556
+ pattern_hash = values.set_values(pattern_hash)
557
+ end
554
558
  results = {}
555
559
  same_values = {}
556
560
  if pattern_hash.kind_of?(Hash) and pattern_hash.size > 0
@@ -617,20 +621,24 @@ class NiceHash
617
621
  if value.size == 1 and values[key].size > 1
618
622
  # for the case value == ['Ford|Newton|Seat'] and values == ['Ford', 'Newton', 'Ford']
619
623
  i= 0
620
- values[key].each do |v|
621
- if value[0].is_a?(Hash)
622
- res = NiceHash.validate([value[0], select_hash_key], v, only_patterns: only_patterns)
623
- else
624
- # for the case {cars: ['Ford|Newton|Seat']}
625
- res = NiceHash.validate([{key => value[0]}, select_hash_key], {key => v}, only_patterns: only_patterns)
626
- #res = {key => res[:doit]} if res.is_a?(Hash) and res.key?(:doit)
627
- array_pattern = true
624
+ if values[key].class == value.class
625
+ values[key].each do |v|
626
+ if value[0].is_a?(Hash)
627
+ res = NiceHash.validate([value[0], select_hash_key], v, only_patterns: only_patterns)
628
+ else
629
+ # for the case {cars: ['Ford|Newton|Seat']}
630
+ res = NiceHash.validate([{key => value[0]}, select_hash_key], {key => v}, only_patterns: only_patterns)
631
+ #res = {key => res[:doit]} if res.is_a?(Hash) and res.key?(:doit)
632
+ array_pattern = true
633
+ end
634
+ if res.size > 0
635
+ results[key] = Array.new() if !results.keys.include?(key)
636
+ results[key][i] = res
637
+ end
638
+ i += 1
628
639
  end
629
- if res.size > 0
630
- results[key] = Array.new() if !results.keys.include?(key)
631
- results[key][i] = res
632
- end
633
- i += 1
640
+ else
641
+ results[key] = false
634
642
  end
635
643
  else
636
644
  i = 0
@@ -936,6 +944,31 @@ class NiceHash
936
944
  return keys.join(".")
937
945
  end
938
946
 
947
+ ##################################################
948
+ # Get all the keys of a hash
949
+ #
950
+ # @param hash [Hash] The hash
951
+ #
952
+ # @return [Array]
953
+ #
954
+ # @example
955
+ # my_hash = { uno: {dos: :tres} }
956
+ # NiceHash.get_all_keys(my_hash)
957
+ # #>[:uno, :dos, :tres]
958
+ ##################################################
959
+ def self.get_all_keys(h)
960
+ h.each_with_object([]) do |(k,v),keys|
961
+ keys << k
962
+ keys.concat(get_all_keys(v)) if v.is_a? Hash
963
+ if v.is_a?(Array)
964
+ v.each do |vv|
965
+ keys.concat(get_all_keys(vv)) if vv.is_a? Hash or vv.is_a? Array
966
+ end
967
+ end
968
+ end
969
+ end
970
+
971
+
939
972
  ##################################################
940
973
  # Deletes the supplied key
941
974
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nice_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.13
4
+ version: 1.12.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz