nice_hash 1.16.1 → 1.17.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dae5a843bb25c0195b0563c21e6751e7c71f8b860cec6ee81a88748f5048cd47
4
- data.tar.gz: c63f13bc76844057b350037c605055e48ecf3895a622a93ae2eabf0cab6a6d76
3
+ metadata.gz: ea6ec325ff1701227b524b3c505ca2fd3a51a9aa14b93500daac933d28a51038
4
+ data.tar.gz: 022c3fb36a242cba72232325fcee90d5aa17ecf98fbc58d30502f68acb439baf
5
5
  SHA512:
6
- metadata.gz: 6252f5ffcd0346673e31475255c9b83585f952b76848f1921fa361a04a454e4851ba49740b28e787589b0c30398759676b754dd6556016169550f356611d4f16
7
- data.tar.gz: 3fc29d8ae093782c16ef79c8bfcf2b29ffab3ef9de7c63c5d1b345df0c3b4260c321536aa18d39295043db153326931c6385fac702f89085f8a2257d8e8f5029
6
+ metadata.gz: 5cf59b5a2e462a627f1a4162cfdcbfe3b3ebb3149a7ac66a5b86273a94a2913bce39b1f910bfe1ffed646a707b4c998100f38297d2193722abd03e9bcee78cb9
7
+ data.tar.gz: 824eff3a37cce48ead2b6527b17c5c0b78e84f591426a3f0934a5964bb302ac0e3b67ec61e31e1c21ab50d3cdea3077564fffeb0b15401beb0f4b9c8e731bcfd
data/README.md CHANGED
@@ -900,6 +900,17 @@ value.is_a?(Boolean) #> true
900
900
  text.is_a?(Boolean) #> false
901
901
 
902
902
  ```
903
+
904
+ #### in?(array)
905
+ Added method in? to all objects that accepts array as a parameter.
906
+
907
+ ```ruby
908
+ 'uno'.in?(['uno','dos']) #> true
909
+ :uno.in? [:uno, :dos] #> true
910
+ 5.in? [1,2,3,4,6] #> false
911
+
912
+ ```
913
+
903
914
  ### Other tools integration
904
915
 
905
916
  #### Tabulo
@@ -60,7 +60,8 @@ class String
60
60
  result = feed_symbols
61
61
  end
62
62
  rescue StandardError => stack
63
- puts stack.to_s
63
+ puts "#{stack.backtrace[-1]} #{stack.to_s}"
64
+ puts stack.backtrace.join("\n\t") if $DEBUG
64
65
  end
65
66
  result
66
67
  end
@@ -292,12 +293,12 @@ class Hash
292
293
  alias patterns pattern_fields
293
294
  end
294
295
 
295
- ###########################################################################
296
- # symbolize hash of arrays and array of hashes
297
- # Taken from gist https://gist.github.com/Integralist/9503099
298
- # Thanks to @integralist
299
- ###########################################################################
300
296
  class Object
297
+ ###########################################################################
298
+ # symbolize hash of arrays and array of hashes
299
+ # Taken from gist https://gist.github.com/Integralist/9503099
300
+ # Thanks to @integralist
301
+ ###########################################################################
301
302
  def deep_symbolize_keys
302
303
  if is_a? Hash
303
304
  return reduce({}) do |memo, (k, v)|
@@ -312,6 +313,14 @@ class Object
312
313
  end
313
314
  self
314
315
  end
316
+
317
+ ###########################################################################
318
+ # include? but the opposite. Check if the object is included on the array
319
+ ###########################################################################
320
+ def in?(array)
321
+ array.include?(self)
322
+ end
323
+
315
324
  end
316
325
 
317
326
  class Array
@@ -23,6 +23,7 @@ class NiceHash
23
23
  # #>true
24
24
  ##################################################
25
25
  def NiceHash.compare_structure(structure, replica, compare_only_if_exist_key = false, patterns = {})
26
+ patterns = {} if patterns.nil?
26
27
  unless structure.class == replica.class or
27
28
  ((structure.is_a?(TrueClass) or structure.is_a?(FalseClass)) and (replica.is_a?(TrueClass) or replica.is_a?(FalseClass)))
28
29
  puts "NiceHash.compare_structure: different object type #{structure.class} is not #{replica.class}. expected: #{structure.inspect}. found: #{replica.inspect}."
@@ -30,6 +31,7 @@ class NiceHash
30
31
  end
31
32
  success = true
32
33
  if structure.is_a?(Hash)
34
+ patterns = {} unless patterns.is_a?(Hash)
33
35
  structure.each do |key, value|
34
36
  if patterns.key?(key) and replica.key?(key)
35
37
  unless (patterns[key].is_a?(Array) and replica[key].is_a?(Array) and replica[key].empty?) or
@@ -147,7 +147,7 @@ class NiceHash
147
147
  end
148
148
  }
149
149
  unless array_pattern or results.include?(key)
150
- if value.size == 1 and values[key].is_a?(Array) and values[key].size > 1
150
+ if value.size == 1 and values[key].is_a?(Array) and values[key].size > 0
151
151
  # for the case value == ['Ford|Newton|Seat'] and values == ['Ford', 'Newton', 'Ford']
152
152
  i = 0
153
153
  if values[key].class == value.class
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.16.1
4
+ version: 1.17.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-08 00:00:00.000000000 Z
11
+ date: 2021-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string_pattern
@@ -36,20 +36,20 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 3.8.0
39
+ version: 3.9.0
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '3.8'
42
+ version: '3.9'
43
43
  type: :development
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 3.8.0
49
+ version: 3.9.0
50
50
  - - "~>"
51
51
  - !ruby/object:Gem::Version
52
- version: '3.8'
52
+ version: '3.9'
53
53
  description: 'NiceHash creates hashes following certain patterns so your testing will
54
54
  be much easier. Parse and filter JSON. You can easily generate all the hashes you
55
55
  want following the criteria you specify. Many other features coming to Hash class