nice_hash 1.5.0 → 1.6.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/README.md +35 -1
- data/lib/nice/hash/add_to_ruby.rb +2 -2
- data/lib/nice_hash.rb +3 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11278d36028f833bcc7ef1265fb425112268758fce86f8743033b86923c7545d
|
4
|
+
data.tar.gz: 6dbc2c7f4f37149b3c79dd00b78df5e411c2d4971cda3a61e79408431012c287
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3b417fabc190632e5910e68ecdb1d80192e0bc25889a16546f263ba6421c675431fe7df1e74cf23e91402e78dd13467e082af1dee7c43b776a35a9e779b411d
|
7
|
+
data.tar.gz: 5e5a0aa355c5552b0febe04d611622e0d57e51e68fd93eecc7bef40504548260b62ee0d159448bac5030c48347430be434bd7bda125947c028eb566ef5bcccb7
|
data/README.md
CHANGED
@@ -537,13 +537,47 @@ array_of_hashes.each {|hash_with_one_wrong_field|
|
|
537
537
|
|
538
538
|
Take a look at a full example: https://gist.github.com/MarioRuiz/824d7a462b62fd85f02c1a09455deefb
|
539
539
|
|
540
|
+
### Adding other values on real time when calling `generate` method
|
541
|
+
|
542
|
+
If you need a value to be supplied for your key on real time everytime you call the `generate` method you can use `lambda`
|
543
|
+
|
544
|
+
```ruby
|
545
|
+
my_hash = {
|
546
|
+
loginname: :"10:Ln",
|
547
|
+
datetime: lambda {
|
548
|
+
Time.now.stamp
|
549
|
+
},
|
550
|
+
other: Time.now.stamp
|
551
|
+
}
|
552
|
+
|
553
|
+
pp my_hash.gen
|
554
|
+
sleep 0.3
|
555
|
+
pp my_hash.gen
|
556
|
+
|
557
|
+
```
|
558
|
+
|
559
|
+
AS you can see in this example the value of the field `datetime` is different every time we generate the hash, but the value of the field `other` is generated the first time and it doesn't change later.
|
560
|
+
|
561
|
+
This is the output:
|
562
|
+
|
563
|
+
```
|
564
|
+
{:loginname=>"dQ1gwPvHHZ",
|
565
|
+
:datetime=>"2019-01-02T13:41:05.536",
|
566
|
+
:other=>"2019-01-02T13:41:05.536"}
|
567
|
+
|
568
|
+
{:loginname=>"WUCnWJmm0o",
|
569
|
+
:datetime=>"2019-01-02T13:41:05.836",
|
570
|
+
:other=>"2019-01-02T13:41:05.536"}
|
571
|
+
```
|
572
|
+
|
573
|
+
|
540
574
|
#### Other useful methods
|
541
575
|
|
542
576
|
In case you need the time stamp, we added the method `stamp` to the `Time` class
|
543
577
|
|
544
578
|
```ruby
|
545
579
|
puts Time.now.stamp
|
546
|
-
#> 2019-01-02T11:03:23.
|
580
|
+
#> 2019-01-02T11:03:23.620
|
547
581
|
```
|
548
582
|
|
549
583
|
In class `Date` we added a very handy `random` method you can use to generate random dates.
|
@@ -118,10 +118,10 @@ end
|
|
118
118
|
|
119
119
|
|
120
120
|
class Time
|
121
|
-
# It will return in the format: '%Y-%m-%dT%H:%M:%S
|
121
|
+
# It will return in the format: '%Y-%m-%dT%H:%M:%S.%L'
|
122
122
|
# Example: puts Time.now.stamp
|
123
123
|
def stamp
|
124
|
-
return self.strftime('%Y-%m-%dT%H:%M:%S
|
124
|
+
return self.strftime('%Y-%m-%dT%H:%M:%S.%L')
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
data/lib/nice_hash.rb
CHANGED
@@ -373,6 +373,8 @@ class NiceHash
|
|
373
373
|
}
|
374
374
|
hash[key]=value_ret
|
375
375
|
end
|
376
|
+
elsif value.kind_of?(Proc)
|
377
|
+
hash[key]=value.call
|
376
378
|
else
|
377
379
|
hash[key]=value
|
378
380
|
end
|
@@ -509,7 +511,7 @@ class NiceHash
|
|
509
511
|
end
|
510
512
|
|
511
513
|
else
|
512
|
-
unless only_patterns
|
514
|
+
unless only_patterns or value.kind_of?(Proc)
|
513
515
|
results[key]=false unless value==values[key]
|
514
516
|
end
|
515
517
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nice_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.5'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
22
|
+
version: 1.5.0
|
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: '1.
|
29
|
+
version: '1.5'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.
|
32
|
+
version: 1.5.0
|
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
|