nice_hash 1.16.0 → 1.17.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 +4 -4
- data/README.md +11 -0
- data/lib/nice/hash/add_to_ruby.rb +14 -6
- data/lib/nice/hash/compare_structure.rb +4 -1
- data/lib/nice/hash/validate.rb +4 -2
- 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: '079c05701a8e28c610bba95e780a15429f12065558f8d82248e88a3c17aacb72'
|
|
4
|
+
data.tar.gz: 7587f70f3047ab34cb2c379e953aa0ab628c18a7aa35170fa08be53604a422a5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c4638aeed2ea149fbe9311d7e13bf28181d054f6a8d65e27087806497601842eab1ae4485c5a5530a8c1237a14f819321288658d37058aa5741f640ec5abfa63
|
|
7
|
+
data.tar.gz: 4d0c539f5df0ff82208c46763862bb6cc2c0e3645454e7216fd47db76fb7a299773ab3dc93fc2f7ffd1a79f8d0d216715284f3f90d05084ea5a26c08bb05b621
|
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,7 @@ 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
64
|
end
|
|
65
65
|
result
|
|
66
66
|
end
|
|
@@ -292,12 +292,12 @@ class Hash
|
|
|
292
292
|
alias patterns pattern_fields
|
|
293
293
|
end
|
|
294
294
|
|
|
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
295
|
class Object
|
|
296
|
+
###########################################################################
|
|
297
|
+
# symbolize hash of arrays and array of hashes
|
|
298
|
+
# Taken from gist https://gist.github.com/Integralist/9503099
|
|
299
|
+
# Thanks to @integralist
|
|
300
|
+
###########################################################################
|
|
301
301
|
def deep_symbolize_keys
|
|
302
302
|
if is_a? Hash
|
|
303
303
|
return reduce({}) do |memo, (k, v)|
|
|
@@ -312,6 +312,14 @@ class Object
|
|
|
312
312
|
end
|
|
313
313
|
self
|
|
314
314
|
end
|
|
315
|
+
|
|
316
|
+
###########################################################################
|
|
317
|
+
# include? but the opposite. Check if the object is included on the array
|
|
318
|
+
###########################################################################
|
|
319
|
+
def in?(array)
|
|
320
|
+
array.include?(self)
|
|
321
|
+
end
|
|
322
|
+
|
|
315
323
|
end
|
|
316
324
|
|
|
317
325
|
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,16 +31,18 @@ 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
|
|
38
|
+
(compare_only_if_exist_key and replica.key?(key) and replica[key].nil?) or
|
|
36
39
|
{key => patterns[key]}.validate({key => replica[key]}).empty?
|
|
37
40
|
puts "NiceHash.compare_structure: key :#{key} not following pattern #{patterns[key]}. value: #{replica[key]}"
|
|
38
41
|
success = false
|
|
39
42
|
end
|
|
40
43
|
end
|
|
41
44
|
|
|
42
|
-
if compare_only_if_exist_key and replica.key?(key)
|
|
45
|
+
if compare_only_if_exist_key and replica.key?(key) and !replica[key].nil?
|
|
43
46
|
unless compare_structure(value, replica[key], compare_only_if_exist_key, patterns)
|
|
44
47
|
puts "NiceHash.compare_structure: key :#{key} different."
|
|
45
48
|
success = false
|
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].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
|
|
@@ -174,10 +174,12 @@ class NiceHash
|
|
|
174
174
|
value.each { |v|
|
|
175
175
|
if v.is_a?(Hash)
|
|
176
176
|
res = NiceHash.validate([v, select_hash_key], values[key][i], only_patterns: only_patterns)
|
|
177
|
-
|
|
177
|
+
elsif v.is_a?(Array)
|
|
178
178
|
# for the case {cars: ['Ford|Newton|Seat']}
|
|
179
179
|
res = NiceHash.validate([{ key => v }, select_hash_key], { key => values[key][i] }, only_patterns: only_patterns)
|
|
180
180
|
array_pattern = true
|
|
181
|
+
else
|
|
182
|
+
res = []
|
|
181
183
|
end
|
|
182
184
|
if res.size > 0
|
|
183
185
|
results[key] = Array.new() if !results.keys.include?(key)
|
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.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:
|
|
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
|