nice_hash 1.13.0 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/nice/hash/add_to_ruby.rb +10 -0
- data/lib/nice_hash.rb +27 -3
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c2618d70584a37e351a02db7c4771aa4feff1264ded1b592d85a392014e7104
|
4
|
+
data.tar.gz: 3ce0ddf1b7dae7709aebb8267ec46d251704d7976184251ce795dbee0abcdc22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eebb8367920fb12254cf9b73deb46fd0391816a34727039871e8f89f6d70434dee02fc658b496e32169c00ae04a9d71853a2ca78d61d7d931444da524e188b74
|
7
|
+
data.tar.gz: db2d81ad6b7b94ec58aff98ccfb471cd09d9c7c036cdaee4fe75a53ee37649f11b5a85fb2a81fae21398482c975c400b712f8dba934937590b34ff8c286d4427
|
data/README.md
CHANGED
@@ -223,6 +223,9 @@ pp NiceHash.set_values(my_hash, { price: 75, beep: false } )
|
|
223
223
|
# using the Hash class
|
224
224
|
pp my_hash.set_values({ price: 75, beep: false })
|
225
225
|
|
226
|
+
# setting specific nested keys
|
227
|
+
pp my_hash.set_values({'data.lab.products.price': 75, 'data.lab.beep': false})
|
228
|
+
|
226
229
|
```
|
227
230
|
|
228
231
|
### Filtering / Selecting an specific key on the hash and subhashes
|
@@ -599,6 +602,7 @@ The possible validation values returned:
|
|
599
602
|
:excluded_data: the resultant string will include one or more characters that should be excluded. It works only if excluded data supplied on the pattern.
|
600
603
|
:string_set_not_allowed: it will include one or more characters that are not supposed to be on the string.
|
601
604
|
|
605
|
+
You can also supply nested pattern keys for the patterns to be more specific: `{'draws.drawId': :"4:N"}`
|
602
606
|
|
603
607
|
### Change only one value at a time and return an Array of Hashes
|
604
608
|
|
@@ -746,7 +750,7 @@ Valid patterns:
|
|
746
750
|
- Boolean: specifying Boolean will check if the value is TrueClass or FalseClass
|
747
751
|
- ranges: Any kind of numeric ranges, for example:
|
748
752
|
- 10..400
|
749
|
-
- 20..50
|
753
|
+
- -20..50
|
750
754
|
- 60.0..500.0
|
751
755
|
- 10.. (from 10 to infinite) Only from Ruby 2.6
|
752
756
|
- DateTime: it will verify if the value is following Time stamp string '2019-06-20T12:01:09.971Z' or if the object is a Time, Date or DateTime class
|
@@ -253,6 +253,16 @@ class Hash
|
|
253
253
|
NiceHash.set_values(self, hash_values)
|
254
254
|
end
|
255
255
|
|
256
|
+
###########################################################################
|
257
|
+
# Search if the hash contains the supplied key
|
258
|
+
# search can be a string, symbol or regexp.
|
259
|
+
# In case of string or symbol it will return true even if only part of the key fits the 'search'
|
260
|
+
###########################################################################
|
261
|
+
def has_rkey?(search)
|
262
|
+
search = Regexp.new(search.to_s) unless search.is_a?(Regexp)
|
263
|
+
!!keys.detect{ |key| key =~ search }
|
264
|
+
end
|
265
|
+
|
256
266
|
alias gen generate
|
257
267
|
alias val validate
|
258
268
|
alias patterns pattern_fields
|
data/lib/nice_hash.rb
CHANGED
@@ -99,6 +99,8 @@ class NiceHash
|
|
99
99
|
# #> {:name=>"Peter", :address=>"\#$$$$$", :city=>"London", :products=> [{:name=>:"10:Ln", :price=>"1000"}, {:name=>:"10:Ln", :price=>"1000"}]}
|
100
100
|
# Using it directly on Hash class, set_values(hash_values):
|
101
101
|
# new_hash = my_hash.set_values({city: 'London', price: '1000'})
|
102
|
+
# Setting specific nested keys
|
103
|
+
# new_hash = my_hash.set_values({'data.lab.products.price': 75, 'data.lab.beep': false})
|
102
104
|
###########################################################################
|
103
105
|
def NiceHash.set_values(hash_array, hash_values)
|
104
106
|
hashv = Hash.new()
|
@@ -107,9 +109,31 @@ class NiceHash
|
|
107
109
|
if hash_values.keys.include?(k)
|
108
110
|
hashv[k] = hash_values[k]
|
109
111
|
elsif v.is_a?(Array)
|
110
|
-
|
112
|
+
if hash_values.has_rkey?('\.') # the kind of 'uno.dos.tres'
|
113
|
+
new_hash_values = {}
|
114
|
+
hash_values.each do |kk,vv|
|
115
|
+
if kk.to_s.match?(/^#{k}\./)
|
116
|
+
kk = kk.to_s.gsub(/^#{k}\./, '').to_sym
|
117
|
+
new_hash_values[kk] = vv
|
118
|
+
end
|
119
|
+
end
|
120
|
+
hashv[k] = NiceHash.set_values(v, new_hash_values)
|
121
|
+
else
|
122
|
+
hashv[k] = NiceHash.set_values(v, hash_values)
|
123
|
+
end
|
111
124
|
elsif v.is_a?(Hash)
|
112
|
-
|
125
|
+
if hash_values.has_rkey?('\.') # the kind of 'uno.dos.tres'
|
126
|
+
new_hash_values = {}
|
127
|
+
hash_values.each do |kk,vv|
|
128
|
+
if kk.to_s.match?(/^#{k}\./)
|
129
|
+
kk = kk.to_s.gsub(/^#{k}\./, '').to_sym
|
130
|
+
new_hash_values[kk] = vv
|
131
|
+
end
|
132
|
+
end
|
133
|
+
hashv[k] = NiceHash.set_values(v, new_hash_values)
|
134
|
+
else
|
135
|
+
hashv[k] = NiceHash.set_values(v, hash_values)
|
136
|
+
end
|
113
137
|
else
|
114
138
|
hashv[k] = v
|
115
139
|
end
|
@@ -602,7 +626,7 @@ class NiceHash
|
|
602
626
|
results[key] = false unless values[key].is_a?(Boolean)
|
603
627
|
elsif value.kind_of?(Regexp)
|
604
628
|
rex = Regexp.new("^#{value}$")
|
605
|
-
unless values[key].match?(rex)
|
629
|
+
unless values[key].to_s.match?(rex)
|
606
630
|
results[key] = false
|
607
631
|
end
|
608
632
|
elsif value.kind_of?(Array)
|
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.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string_pattern
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.2'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 2.1
|
22
|
+
version: 2.2.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '2.
|
29
|
+
version: '2.2'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 2.1
|
32
|
+
version: 2.2.1
|
33
33
|
description: 'NiceHash creates hashes following certain patterns so your testing will
|
34
34
|
be much easier. Parse and filter JSON. You can easily generate all the hashes you
|
35
35
|
want following the criteria you specify. Many other features coming to Hash class
|
@@ -67,8 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
requirements: []
|
70
|
-
|
71
|
-
rubygems_version: 2.7.6
|
70
|
+
rubygems_version: 3.0.3
|
72
71
|
signing_key:
|
73
72
|
specification_version: 4
|
74
73
|
summary: NiceHash creates hashes following certain patterns so your testing will be
|