nice_hash 1.16.1 → 1.17.2
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 +4 -4
- data/README.md +11 -0
- data/lib/nice/hash/add_to_ruby.rb +15 -6
- data/lib/nice/hash/compare_structure.rb +2 -0
- data/lib/nice/hash/validate.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ea6ec325ff1701227b524b3c505ca2fd3a51a9aa14b93500daac933d28a51038
|
|
4
|
+
data.tar.gz: 022c3fb36a242cba72232325fcee90d5aa17ecf98fbc58d30502f68acb439baf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
data/lib/nice/hash/validate.rb
CHANGED
|
@@ -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 >
|
|
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.
|
|
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:
|
|
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.
|
|
39
|
+
version: 3.9.0
|
|
40
40
|
- - "~>"
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: '3.
|
|
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.
|
|
49
|
+
version: 3.9.0
|
|
50
50
|
- - "~>"
|
|
51
51
|
- !ruby/object:Gem::Version
|
|
52
|
-
version: '3.
|
|
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
|