nice_hash 1.3.0 → 1.4.0
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/.yardopts +4 -4
- data/LICENSE +21 -21
- data/README.md +547 -545
- data/lib/nice/hash/add_to_ruby.rb +204 -189
- data/lib/nice_hash.rb +710 -710
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 198976c9f4162265f67630f31179f40cd2820709edbe600fedc42cc5fbfd0133
|
|
4
|
+
data.tar.gz: 4b59639f747fdd7db4c4aadc45f49d0554d1d60da9f7bfd99f5bc704ef908053
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9948d955b32f8e7f69f05b1ec8445b5564bc3cba6e36f812a6536bee2a89bcbb3bf3f69cda4cbbdf3f2b288af519790a76c5c7c395343529ef645399150f48b4
|
|
7
|
+
data.tar.gz: 8e26a5461d5ff343889fe2c6f22271722387ae543d751380ae268b7876d51bdbab674e1d4e278676f3019815ace57c81c3deac61b8ee0772bba22d5168ea42f1
|
data/.yardopts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
--readme README.md
|
|
2
|
-
--title 'nice_hash - NiceHash creates hashes following certain patterns so your testing will be much easier. You can easily generates all the hashes you want following the criteria you specify.'
|
|
3
|
-
--charset utf-8
|
|
4
|
-
--markup markdown
|
|
1
|
+
--readme README.md
|
|
2
|
+
--title 'nice_hash - NiceHash creates hashes following certain patterns so your testing will be much easier. You can easily generates all the hashes you want following the criteria you specify.'
|
|
3
|
+
--charset utf-8
|
|
4
|
+
--markup markdown
|
|
5
5
|
'lib/**/*.rb' - '*.md' - 'LICENSE'
|
data/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2017 Mario Ruiz
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Mario Ruiz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,545 +1,547 @@
|
|
|
1
|
-
# NiceHash
|
|
2
|
-
|
|
3
|
-
[](https://rubygems.org/gems/nice_hash)
|
|
4
|
-
|
|
5
|
-
NiceHash creates hashes following certain patterns so your testing will be much easier.
|
|
6
|
-
|
|
7
|
-
You can easily generates all the hashes you want following the criteria you specify.
|
|
8
|
-
|
|
9
|
-
Many other features coming to Hash class like the methods 'bury' or select_key, access the keys like methods: my_hash.my_key.other_key. You will be able to generate thousands of different hashes just declaring one and test easily APIs based on JSON for example.
|
|
10
|
-
|
|
11
|
-
You can also parse and filter a json string very easily.
|
|
12
|
-
|
|
13
|
-
To generate the strings following a pattern take a look at the documentation for string_pattern gem: https://github.com/MarioRuiz/string_pattern
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
my_hash
|
|
127
|
-
puts my_hash.
|
|
128
|
-
|
|
129
|
-
puts my_hash.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
my_hash.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
puts my_hash.
|
|
141
|
-
puts my_hash.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
puts my_hash.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
puts new_hash.get_values(:
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
#using
|
|
169
|
-
new_hash =
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
#filtering
|
|
216
|
-
new_hash = NiceHash.generate(my_hash
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
#filtering
|
|
224
|
-
new_hash = my_hash.generate
|
|
225
|
-
#filtering by a key
|
|
226
|
-
new_hash = my_hash.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
:
|
|
237
|
-
:
|
|
238
|
-
:
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
:
|
|
243
|
-
|
|
244
|
-
:
|
|
245
|
-
|
|
246
|
-
:
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
:
|
|
250
|
-
:
|
|
251
|
-
:
|
|
252
|
-
:
|
|
253
|
-
:
|
|
254
|
-
:
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
:
|
|
268
|
-
:
|
|
269
|
-
:
|
|
270
|
-
:
|
|
271
|
-
:
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
wrong_min_length = my_hash.
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
:
|
|
294
|
-
:
|
|
295
|
-
:
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
:
|
|
299
|
-
:
|
|
300
|
-
:
|
|
301
|
-
:
|
|
302
|
-
:
|
|
303
|
-
:
|
|
304
|
-
:
|
|
305
|
-
:
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
[:
|
|
329
|
-
[:
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
[:
|
|
339
|
-
[:
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
[:
|
|
349
|
-
[:
|
|
350
|
-
[:draws, 0, :
|
|
351
|
-
[:draws,
|
|
352
|
-
[:draws,
|
|
353
|
-
[:draws, 1, :
|
|
354
|
-
[:
|
|
355
|
-
[:
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
[:
|
|
365
|
-
[:
|
|
366
|
-
[:draws, 0, :
|
|
367
|
-
[:draws,
|
|
368
|
-
[:draws,
|
|
369
|
-
[:draws, 1, :
|
|
370
|
-
[:
|
|
371
|
-
[:
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
patterns.
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
value = min_length_error.dig(
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
the value: '
|
|
402
|
-
|
|
403
|
-
the value: '
|
|
404
|
-
the value: '
|
|
405
|
-
the value: '
|
|
406
|
-
the value: '
|
|
407
|
-
the value: '
|
|
408
|
-
the value: '
|
|
409
|
-
the value: '
|
|
410
|
-
the value: '
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
default_values.
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
:
|
|
428
|
-
:
|
|
429
|
-
:
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
:
|
|
434
|
-
|
|
435
|
-
:
|
|
436
|
-
|
|
437
|
-
:
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
:
|
|
441
|
-
:
|
|
442
|
-
:
|
|
443
|
-
:
|
|
444
|
-
:
|
|
445
|
-
:
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
:
|
|
461
|
-
:
|
|
462
|
-
:
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
:
|
|
467
|
-
|
|
468
|
-
:
|
|
469
|
-
|
|
470
|
-
:
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
:
|
|
474
|
-
:
|
|
475
|
-
:
|
|
476
|
-
:
|
|
477
|
-
:
|
|
478
|
-
:
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
:
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
:
|
|
509
|
-
:
|
|
510
|
-
:
|
|
511
|
-
:
|
|
512
|
-
:
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
array_of_hashes.
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
#
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
1
|
+
# NiceHash
|
|
2
|
+
|
|
3
|
+
[](https://rubygems.org/gems/nice_hash)
|
|
4
|
+
|
|
5
|
+
NiceHash creates hashes following certain patterns so your testing will be much easier.
|
|
6
|
+
|
|
7
|
+
You can easily generates all the hashes you want following the criteria you specify.
|
|
8
|
+
|
|
9
|
+
Many other features coming to Hash class like the methods 'bury' or select_key, access the keys like methods: my_hash.my_key.other_key. You will be able to generate thousands of different hashes just declaring one and test easily APIs based on JSON for example.
|
|
10
|
+
|
|
11
|
+
You can also parse and filter a json string very easily.
|
|
12
|
+
|
|
13
|
+
To generate the strings following a pattern take a look at the documentation for string_pattern gem: https://github.com/MarioRuiz/string_pattern
|
|
14
|
+
|
|
15
|
+
To use nice_hash on Http connections take a look at nice_http gem: https://github.com/MarioRuiz/nice_http
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Add this line to your application's Gemfile:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
gem 'nice_hash'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
And then execute:
|
|
26
|
+
|
|
27
|
+
$ bundle
|
|
28
|
+
|
|
29
|
+
Or install it yourself as:
|
|
30
|
+
|
|
31
|
+
$ gem install nice_hash
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
Remember!! To generate the strings following a pattern take a look at the documentation for string_pattern gem: https://github.com/MarioRuiz/string_pattern
|
|
36
|
+
|
|
37
|
+
This is he Hash we will be using on our examples:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
|
|
41
|
+
require 'nice_hash'
|
|
42
|
+
|
|
43
|
+
my_hash={
|
|
44
|
+
loginame: :"5-10:/xn/",
|
|
45
|
+
[:pwd1, :pwd2, :pwd3] => :"5-10:L/n/",
|
|
46
|
+
name: :"10-20:T_/x/",
|
|
47
|
+
draws: [
|
|
48
|
+
{
|
|
49
|
+
drawId: :"5:N",
|
|
50
|
+
drawName: :"10:Ln",
|
|
51
|
+
type: :"Weekely|Daily",
|
|
52
|
+
owner: {
|
|
53
|
+
default: 'admin',
|
|
54
|
+
correct: :"20:L"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
drawId: :"5:N",
|
|
59
|
+
drawName: :"10:Ln",
|
|
60
|
+
type: :"Weekely|Daily",
|
|
61
|
+
owner: {
|
|
62
|
+
default: 'admin',
|
|
63
|
+
correct: :"20:L"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
zip: {default: '00000', correct: :'5:N'},
|
|
68
|
+
address: "21 Doom Av",
|
|
69
|
+
city: {
|
|
70
|
+
default: "Madrid",
|
|
71
|
+
correct: "London|Rome"
|
|
72
|
+
},
|
|
73
|
+
wagers: ['34AAB', 'dfffDD', '33499A'],
|
|
74
|
+
country: {default: 'Spain', correct: ["Spain", "Iceland", "Serbia", "Denmark", "Canada", "Italy", "Austria"].join("|")}, #one of these values
|
|
75
|
+
mobilePhone: {default: '(987)654321', correct: ['(', :'3:N', ')', :'6-8:N']},
|
|
76
|
+
sex: :"male|female|other", #any of these values
|
|
77
|
+
display: true
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Explanations of the different fields:
|
|
82
|
+
|
|
83
|
+
loginname: from 5 to 10 characters, mandatory to have lower letters and numbers
|
|
84
|
+
pwd, pwd2, pwd3: will have the same value. The value from 5 to 10 chars, optional capital and lower letters, necessary to contain numbers
|
|
85
|
+
name: from 10 to 20 chars. Optional national characters and space, necessary lower letters.
|
|
86
|
+
drawId: 5 numbers
|
|
87
|
+
drawName: 10 letters and/or numbers
|
|
88
|
+
type: 'Weekely' or 'Daily'
|
|
89
|
+
owner: correct: 20 letters
|
|
90
|
+
zip: correct: 5 numbers
|
|
91
|
+
city: correct: 'London' or 'Rome'
|
|
92
|
+
country: correct: one of these values "Spain", "Iceland", "Serbia", "Denmark", "Canada", "Italy", "Austria"
|
|
93
|
+
mobilePhone: correct: a sting pattern with one of the next: "(nnn) nnnnnn", "(nnn) nnnnnnn", "(nnn) nnnnnnnn"
|
|
94
|
+
sex: 'male' or 'female' or 'other'
|
|
95
|
+
|
|
96
|
+
So in case you want to assign to a key a string pattern value like for example in loginame, you need to specify the string pattern as a symbol :"5-10:/xn/"
|
|
97
|
+
|
|
98
|
+
You can also supply an array of strings and string patterns, like on mobilePhone.correct: ['(', :'3:N', ')', :'6-8:N']}
|
|
99
|
+
|
|
100
|
+
Also you can specify to select one of the values you want by separating them with |, like for example on sex field: "male|female|other"
|
|
101
|
+
|
|
102
|
+
In case you want one pattern to be generated with unique values, so never repeat the same value for that particular pattern, use a symbol object pattern and add to the end of the pattern the symbol: &
|
|
103
|
+
|
|
104
|
+
```ruby
|
|
105
|
+
|
|
106
|
+
loginame: :"5-10:/xn/&",
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Also if you have a JSON string you want to parse it and get the values of certain keys you can use the json method we added to nice_hash:
|
|
111
|
+
|
|
112
|
+
```ruby
|
|
113
|
+
my_json_string="{\"id\":344,\"customer\":{\"name\":\"Peter Smith\",\"phone\":334334333},\"tickets\":[{\"idt\":345,\"name\":\"myFavor1\"},{\"idt\":3123},{\"idt\":3145,\"name\":\"Special ticket\"}]}"
|
|
114
|
+
puts my_json_string.json(:idt)
|
|
115
|
+
#> [345, 3123, 3145]
|
|
116
|
+
|
|
117
|
+
puts my_json_string.json(:idt, :name)
|
|
118
|
+
#> {:name=>["Peter Smith", ["myFavor1", "Special ticket"]], :idt=>[345, 3123, 3145]}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### How to access the different keys
|
|
122
|
+
|
|
123
|
+
You can access the keys of the hash like always, but now we added to the Hash class the posibility of accessing it using:
|
|
124
|
+
|
|
125
|
+
```ruby
|
|
126
|
+
puts my_hash[:address] # like usually is done
|
|
127
|
+
puts my_hash.address
|
|
128
|
+
my_hash.address = '99 Danish Street' #assignment
|
|
129
|
+
puts my_hash.loginame
|
|
130
|
+
puts my_hash.mobilePhone.correct
|
|
131
|
+
puts my_hash.draws[1].owner.correct
|
|
132
|
+
```
|
|
133
|
+
Also another way to access the different keys is by adding first underscore.
|
|
134
|
+
By doing it this way we are avoiding the cases where already exists a method with the same name on Hash class, for example: zip, display, default, select...
|
|
135
|
+
|
|
136
|
+
```ruby
|
|
137
|
+
puts my_hash._address
|
|
138
|
+
my_hash._address = '99 Danish Street' #assignment
|
|
139
|
+
my_hash._display = false #assignment
|
|
140
|
+
puts my_hash._loginame
|
|
141
|
+
puts my_hash._mobilePhone._correct
|
|
142
|
+
puts my_hash._draws[1]._owner._correct
|
|
143
|
+
puts my_hash._zip.correct #you can mix both also
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
By using the string_pattern gem you can generate single strings following the specific pattern on the field:
|
|
147
|
+
|
|
148
|
+
```ruby
|
|
149
|
+
puts my_hash.loginame.generate #>s93owuvkh
|
|
150
|
+
puts my_hash.mobilePhone.correct.generate #>(039)5669558
|
|
151
|
+
puts my_hash._zip._correct.gen # gen is an alias for generate method #>84584
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
If you want to search for all the values of one or more keys use get_values method:
|
|
155
|
+
|
|
156
|
+
```ruby
|
|
157
|
+
new_hash = my_hash.generate
|
|
158
|
+
puts new_hash.get_values(:address) #> {:address=>"21 Doom Av"}
|
|
159
|
+
puts new_hash.get_values(:address, :zip) #> {:zip=>{:default=>"00000", :correct=>"42782"}, :address=>"21 Doom Av"}
|
|
160
|
+
puts new_hash.get_values(:drawId) #> {:drawId=>["84914", "21158"]}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Filtering / Selecting an specific key on the hash and subhashes
|
|
164
|
+
|
|
165
|
+
In case you supply different possibilities to be used like for example on fields: owner, zip, city and mobilePhone, and you one to use a concrete one, use the method select_key
|
|
166
|
+
|
|
167
|
+
```ruby
|
|
168
|
+
#using NiceHash class
|
|
169
|
+
new_hash = NiceHash.select_key(my_hash, :correct)
|
|
170
|
+
#using select_key method on Hash class
|
|
171
|
+
new_hash = my_hash.select_key(:correct)
|
|
172
|
+
default_hash = my_hash.select_key(:default)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
On this example new_hash will contain:
|
|
176
|
+
|
|
177
|
+
```ruby
|
|
178
|
+
{
|
|
179
|
+
loginame: :"5-10:/xn/",
|
|
180
|
+
[:pwd1, :pwd2, :pwd3] => :"5-10:L/n/",
|
|
181
|
+
name: :"10-20:T_/x/",
|
|
182
|
+
draws: [
|
|
183
|
+
{
|
|
184
|
+
drawId: :"5:N",
|
|
185
|
+
drawName: :"10:Ln",
|
|
186
|
+
type: :"Weekely|Daily",
|
|
187
|
+
owner: :"20:L"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
drawId: :"5:N",
|
|
191
|
+
drawName: :"10:Ln",
|
|
192
|
+
type: :"Weekely|Daily",
|
|
193
|
+
owner: :"20:L"
|
|
194
|
+
}
|
|
195
|
+
],
|
|
196
|
+
zip: :'5:N',
|
|
197
|
+
address: "21 Doom Av",
|
|
198
|
+
city: "London|Rome",
|
|
199
|
+
wagers: ['34AAB', 'dfffDD', '33499A'],
|
|
200
|
+
country: ["Spain", "Iceland", "Serbia", "Denmark", "Canada", "Italy", "Austria"].join("|"), #one of these values
|
|
201
|
+
mobilePhone: ['(', :'3:N', ')', :'6-8:N'],
|
|
202
|
+
sex: :"male|female|other", #any of these values
|
|
203
|
+
display: true
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### How to generate the hash with the criteria we want
|
|
208
|
+
|
|
209
|
+
You can use the 'generate' method and everytime will be generated a different hash with different values.
|
|
210
|
+
|
|
211
|
+
Remember you can filter/select by a hash key
|
|
212
|
+
|
|
213
|
+
Using the NiceHash class:
|
|
214
|
+
```ruby
|
|
215
|
+
#without filtering
|
|
216
|
+
new_hash = NiceHash.generate(my_hash)
|
|
217
|
+
#filtering by a key passing the key on parameters
|
|
218
|
+
new_hash = NiceHash.generate(my_hash, :correct)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Using Hash class (you can use the alias 'gen' for 'generate'):
|
|
222
|
+
```ruby
|
|
223
|
+
#without filtering
|
|
224
|
+
new_hash = my_hash.generate
|
|
225
|
+
#filtering by a key passing the key on parameters
|
|
226
|
+
new_hash = my_hash.generate(:correct)
|
|
227
|
+
#filtering by a key using select_key method
|
|
228
|
+
new_hash = my_hash.select_key(:correct).generate
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
In case of filtering by :correct new_hash would have a value like this for example:
|
|
233
|
+
|
|
234
|
+
```ruby
|
|
235
|
+
{:loginame=>"s45x029o",
|
|
236
|
+
:pwd1=>"E6hz9YS7",
|
|
237
|
+
:pwd2=>"E6hz9YS7",
|
|
238
|
+
:pwd3=>"E6hz9YS7",
|
|
239
|
+
:name=>"OyTQNfEyPOzVYMxPym",
|
|
240
|
+
:draws=>
|
|
241
|
+
[{:drawId=>"54591",
|
|
242
|
+
:drawName=>"cr5Q7pq4G8",
|
|
243
|
+
:type=>"Weekely",
|
|
244
|
+
:owner=>"nKEasYWInPGJxxElBZUB"},
|
|
245
|
+
{:drawId=>"73307",
|
|
246
|
+
:drawName=>"FnHPM4CsRC",
|
|
247
|
+
:type=>"Weekely",
|
|
248
|
+
:owner=>"cNGpHDhDLcxSFbOGqvNy"}],
|
|
249
|
+
:zip=>"47537",
|
|
250
|
+
:address=>"21 Doom Av",
|
|
251
|
+
:city=>"London",
|
|
252
|
+
:wagers=>["34AAB", "dfffDD", "33499A"],
|
|
253
|
+
:country=>"Denmark",
|
|
254
|
+
:mobilePhone=>"(707)8782080",
|
|
255
|
+
:sex=>"male",
|
|
256
|
+
:display=>true}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
In case no filtering you will get all the values for all keys
|
|
260
|
+
|
|
261
|
+
### How to generate the hash with wrong values for the string patterns specified on the hash
|
|
262
|
+
|
|
263
|
+
We can generate wrong values passing the keyword argument: expected_errors (alias: errors)
|
|
264
|
+
|
|
265
|
+
The possible values you can specify is one or more of these ones: :length, :min_length, :max_length, :value, :required_data, :excluded_data, :string_set_not_allowed
|
|
266
|
+
|
|
267
|
+
:length: wrong length, minimum or maximum
|
|
268
|
+
:min_length: wrong minimum length
|
|
269
|
+
:max_length: wrong maximum length
|
|
270
|
+
:value: wrong resultant value
|
|
271
|
+
:required_data: the output string won't include all necessary required data. It works only if required data supplied on the pattern.
|
|
272
|
+
: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.
|
|
273
|
+
:string_set_not_allowed: it will include one or more characters that are not supposed to be on the string.
|
|
274
|
+
|
|
275
|
+
Examples:
|
|
276
|
+
|
|
277
|
+
```ruby
|
|
278
|
+
wrong_values = my_hash.generate(:correct, expected_errors: [:value])
|
|
279
|
+
|
|
280
|
+
wrong_max_length = my_hash.generate(:correct, errors: :max_length)
|
|
281
|
+
|
|
282
|
+
wrong_min_length = my_hash.generate(:correct, expected_errors: :min_length)
|
|
283
|
+
|
|
284
|
+
wrong_min_length = my_hash.select_key(:correct).generate(errors: :min_length)
|
|
285
|
+
|
|
286
|
+
valid_values = my_hash.generate(:correct)
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
On this example wrong_min_length will contain something like:
|
|
290
|
+
|
|
291
|
+
```ruby
|
|
292
|
+
{:loginame=>"0u",
|
|
293
|
+
:pwd1=>"4XDx",
|
|
294
|
+
:pwd2=>"4XDx",
|
|
295
|
+
:pwd3=>"4XDx",
|
|
296
|
+
:name=>"bU",
|
|
297
|
+
:draws=>
|
|
298
|
+
[{:drawId=>"", :drawName=>"P03AgdMqV", :type=>"Dail", :owner=>"dYzLRMCnVc"},
|
|
299
|
+
{:drawId=>"", :drawName=>"qw", :type=>"Dail", :owner=>"zkHhTEzM"}],
|
|
300
|
+
:zip=>"7168",
|
|
301
|
+
:address=>"21 Doom Av",
|
|
302
|
+
:city=>"Rom",
|
|
303
|
+
:wagers=>["34AAB", "dfffDD", "33499A"],
|
|
304
|
+
:country=>"Spai",
|
|
305
|
+
:mobilePhone=>"(237)17640431",
|
|
306
|
+
:sex=>"mal",
|
|
307
|
+
:display=>true}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Return the select_fields or the pattern_fields
|
|
311
|
+
|
|
312
|
+
If you need a list of select fields or pattern fields that exist on your hash you can use the methods: select_fields and pattern_fields
|
|
313
|
+
|
|
314
|
+
It will return an array with all the fields found. On every entry of the array you will see keys to the field.
|
|
315
|
+
|
|
316
|
+
```ruby
|
|
317
|
+
all_select_fields = my_hash.select_fields
|
|
318
|
+
select_fields_on_correct = my_hash.select_fields(:correct)
|
|
319
|
+
|
|
320
|
+
all_pattern_fields = my_hash.pattern_fields
|
|
321
|
+
pattern_fields_on_correct = my_hash.pattern_fields(:correct)
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
all_select_fields contains:
|
|
325
|
+
|
|
326
|
+
```ruby
|
|
327
|
+
[[:draws, 0, :type],
|
|
328
|
+
[:draws, 1, :type],
|
|
329
|
+
[:city, :correct],
|
|
330
|
+
[:country, :correct],
|
|
331
|
+
[:sex]]
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
select_fields_on_correct contains:
|
|
335
|
+
|
|
336
|
+
```ruby
|
|
337
|
+
[[:draws, 0, :type],
|
|
338
|
+
[:draws, 1, :type],
|
|
339
|
+
[:city],
|
|
340
|
+
[:country],
|
|
341
|
+
[:sex]]
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
all_pattern_fields contains:
|
|
345
|
+
|
|
346
|
+
```ruby
|
|
347
|
+
[[:loginame],
|
|
348
|
+
[[:pwd1, :pwd2, :pwd3]],
|
|
349
|
+
[:name],
|
|
350
|
+
[:draws, 0, :drawId],
|
|
351
|
+
[:draws, 0, :drawName],
|
|
352
|
+
[:draws, 0, :owner, :correct],
|
|
353
|
+
[:draws, 1, :drawId],
|
|
354
|
+
[:draws, 1, :drawName],
|
|
355
|
+
[:draws, 1, :owner, :correct],
|
|
356
|
+
[:zip, :correct],
|
|
357
|
+
[:mobilePhone, :correct]]
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
pattern_fields_on_correct contains:
|
|
361
|
+
|
|
362
|
+
```ruby
|
|
363
|
+
[[:loginame],
|
|
364
|
+
[[:pwd1, :pwd2, :pwd3]],
|
|
365
|
+
[:name],
|
|
366
|
+
[:draws, 0, :drawId],
|
|
367
|
+
[:draws, 0, :drawName],
|
|
368
|
+
[:draws, 0, :owner],
|
|
369
|
+
[:draws, 1, :drawId],
|
|
370
|
+
[:draws, 1, :drawName],
|
|
371
|
+
[:draws, 1, :owner],
|
|
372
|
+
[:zip],
|
|
373
|
+
[:mobilePhone]]
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
#### dig and bury Hash methods
|
|
378
|
+
In case you want to access the values on a hash structure by using the key array location, you can use the 'dig' method on the Hash class:
|
|
379
|
+
|
|
380
|
+
```ruby
|
|
381
|
+
min_length_error = my_hash.generate :correct, errors: :min_length
|
|
382
|
+
|
|
383
|
+
patterns = my_hash.pattern_fields :correct
|
|
384
|
+
|
|
385
|
+
patterns.each{|key|
|
|
386
|
+
if key[0].kind_of?(Array) # same values, like in pwd1, pwd2 and pwd3
|
|
387
|
+
puts "#{key} same values"
|
|
388
|
+
value = min_length_error.dig(key[0][0])
|
|
389
|
+
else
|
|
390
|
+
value = min_length_error.dig(*key)
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
pattern = my_hash.select_key(:correct).dig(*key)
|
|
394
|
+
puts "the value: '#{value}' was generated from the key: #{key} with pattern: #{pattern}"
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
This returns something like:
|
|
399
|
+
|
|
400
|
+
```
|
|
401
|
+
the value: '5z' was generated from the key: [:loginame] with pattern: 5-10:/xn/
|
|
402
|
+
[[:pwd1, :pwd2, :pwd3]] same values
|
|
403
|
+
the value: '5' was generated from the key: [[:pwd1, :pwd2, :pwd3]] with pattern: 5-10:L/n/
|
|
404
|
+
the value: 'KshiYAmp' was generated from the key: [:name] with pattern: 10-20:T_/x/
|
|
405
|
+
the value: '722' was generated from the key: [:draws, 0, :drawId] with pattern: 5:N
|
|
406
|
+
the value: '4' was generated from the key: [:draws, 0, :drawName] with pattern: 10:Ln
|
|
407
|
+
the value: 'jhVZkII' was generated from the key: [:draws, 0, :owner] with pattern: 20:L
|
|
408
|
+
the value: '260' was generated from the key: [:draws, 1, :drawId] with pattern: 5:N
|
|
409
|
+
the value: 'ssty8hlnJ' was generated from the key: [:draws, 1, :drawName] with pattern: 10:Ln
|
|
410
|
+
the value: 'zPvcwOyyXvWSgNHsuv' was generated from the key: [:draws, 1, :owner] with pattern: 20:L
|
|
411
|
+
the value: '242' was generated from the key: [:zip] with pattern: 5:N
|
|
412
|
+
the value: '(91)7606' was generated from the key: [:mobilePhone] with pattern: ["(", :"3:N", ")", :"6-8:N"]
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
Ruby Hash class doesn't have a method to allocate a value using the key array location so we added to Hash class a method for that purpose, the 'bury' method.
|
|
416
|
+
|
|
417
|
+
```ruby
|
|
418
|
+
default_values = my_hash.generate :default
|
|
419
|
+
|
|
420
|
+
default_values.bury([:draws, 0, :drawName], "FirstDraw")
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
After using the bury method default_values will contain:
|
|
424
|
+
|
|
425
|
+
```ruby
|
|
426
|
+
{:loginame=>"i0v2jy",
|
|
427
|
+
:pwd1=>"x33exx",
|
|
428
|
+
:pwd2=>"x33exx",
|
|
429
|
+
:pwd3=>"x33exx",
|
|
430
|
+
:name=>"HdmsjLxlEgYIFY",
|
|
431
|
+
:draws=>
|
|
432
|
+
[{:drawId=>"12318",
|
|
433
|
+
:drawName=>"FirstDraw",
|
|
434
|
+
:type=>"Weekely",
|
|
435
|
+
:owner=>"admin"},
|
|
436
|
+
{:drawId=>"18947",
|
|
437
|
+
:drawName=>"LPgf2ZQvkG",
|
|
438
|
+
:type=>"Weekely",
|
|
439
|
+
:owner=>"admin"}],
|
|
440
|
+
:zip=>"00000",
|
|
441
|
+
:address=>"21 Doom Av",
|
|
442
|
+
:city=>"Madrid",
|
|
443
|
+
:wagers=>["34AAB", "dfffDD", "33499A"],
|
|
444
|
+
:country=>"Spain",
|
|
445
|
+
:mobilePhone=>"(987)654321",
|
|
446
|
+
:sex=>"male",
|
|
447
|
+
:display=>true}
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
### Validating hashes
|
|
451
|
+
|
|
452
|
+
If you have a Hash that should follow the patterns you specified (in this example declared on my_hash) and you want to validate, then use the 'validate' method.
|
|
453
|
+
|
|
454
|
+
This is particulary useful to test REST APIs responses in JSON
|
|
455
|
+
|
|
456
|
+
If we have a hash with these values:
|
|
457
|
+
|
|
458
|
+
```ruby
|
|
459
|
+
{:loginame=>"rdewvqur",
|
|
460
|
+
:pwd1=>"d3ulo",
|
|
461
|
+
:pwd2=>"d3ulo",
|
|
462
|
+
:pwd3=>"d3ulo",
|
|
463
|
+
:name=>"LTqVKxxFCTqpkdjFkxU",
|
|
464
|
+
:draws=>
|
|
465
|
+
[{:drawId=>"54a43",
|
|
466
|
+
:drawName=>"h3F24yjMWp",
|
|
467
|
+
:type=>"Daily",
|
|
468
|
+
:owner=>"abIZMRxTDsWjQcpdspZt"},
|
|
469
|
+
{:drawId=>"13010",
|
|
470
|
+
:drawName=>"NurCEAtE1M",
|
|
471
|
+
:type=>"Daily",
|
|
472
|
+
:owner=>"vSVoqtSzHkbvRNyJoYGz"}],
|
|
473
|
+
:zip=>"30222",
|
|
474
|
+
:address=>"21 Doom Av",
|
|
475
|
+
:city=>"New York",
|
|
476
|
+
:wagers=>["34AAB", "dfffDD", "33499A"],
|
|
477
|
+
:country=>"Iceland",
|
|
478
|
+
:mobilePhone=>"(441)97037845",
|
|
479
|
+
:sex=>"male",
|
|
480
|
+
:display=>true}
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
To validate those values taking in consideration was is stated on my_hash:
|
|
484
|
+
|
|
485
|
+
```ruby
|
|
486
|
+
results_all_fields = my_hash.validate :correct, values
|
|
487
|
+
|
|
488
|
+
results_pattern_fields = my_hash.validate_patterns :correct, values
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
results_all_fields will contain all the validation errors:
|
|
492
|
+
|
|
493
|
+
```ruby
|
|
494
|
+
{:loginame=>[:value, :required_data],
|
|
495
|
+
:draws=>[{:drawId=>[:value, :string_set_not_allowed]}],
|
|
496
|
+
:city=>false}
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
and results_pattern_fields will contain only the validation errors for the fields containing patterns:
|
|
500
|
+
|
|
501
|
+
```ruby
|
|
502
|
+
{:loginame=>[:value, :required_data],
|
|
503
|
+
:draws=>[{:drawId=>[:value, :string_set_not_allowed]}]}
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
The possible validation values returned:
|
|
507
|
+
|
|
508
|
+
:length: wrong length, minimum or maximum
|
|
509
|
+
:min_length: wrong minimum length
|
|
510
|
+
:max_length: wrong maximum length
|
|
511
|
+
:value: wrong resultant value
|
|
512
|
+
:required_data: the output string won't include all necessary required data. It works only if required data supplied on the pattern.
|
|
513
|
+
: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.
|
|
514
|
+
:string_set_not_allowed: it will include one or more characters that are not supposed to be on the string.
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
### Change only one value at a time and return an Array of Hashes
|
|
518
|
+
|
|
519
|
+
Let's guess we need to test a typical registration REST service and the service has many fields with many validations but we want to test it one field at a time.
|
|
520
|
+
|
|
521
|
+
Then the best thing you can do is to use the method NiceHash.change_one_by_one.
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
```ruby
|
|
525
|
+
|
|
526
|
+
wrong_min_length_hash = my_hash.generate(:correct, errors: :min_length)
|
|
527
|
+
|
|
528
|
+
array_of_hashes = NiceHash.change_one_by_one([my_hash, :correct], wrong_min_length_hash)
|
|
529
|
+
|
|
530
|
+
array_of_hashes.each {|hash_with_one_wrong_field|
|
|
531
|
+
#Here your code to send through http the JSON data stored in hash_with_one_wrong_field
|
|
532
|
+
|
|
533
|
+
#if you want to know which field is the one that is wrong:
|
|
534
|
+
res = my_hash.validate(:correct, hash_with_one_wrong_field)
|
|
535
|
+
}
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
## Contributing
|
|
539
|
+
|
|
540
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/marioruiz/nice_hash.
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
## License
|
|
544
|
+
|
|
545
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
546
|
+
|
|
547
|
+
|