nice_hash 1.4.1 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bfc475fcd6221bb7c896f23036b4357a95c7a532f040e8c2667b850e2e6ae7b
4
- data.tar.gz: 1a40382e50cacda36e441b86341b0de09ad04019e018db8c922e419611590bf2
3
+ metadata.gz: e962f4beb56c312d07d2b31c88df6b05728b38196a88424ac273f67916578dc9
4
+ data.tar.gz: 4c1b994f9157d76fd2ec4d82d27599150641bcc7fbfc3f97b3e5f8e8f108e28d
5
5
  SHA512:
6
- metadata.gz: be8ee3248364c5dea791788e6334f058712b83e78257d0094a8f761fec28bd05bad4fcb8ddb940569151c2cc22f392d42b550ffa5aa07e7e838cbd8b54acc163
7
- data.tar.gz: 636ca1c3698c07b29dd57459c2dc75443c12a21c5e238bcee2a7f64d6c3489fc34588b8ea4f7a7fe9a87c11d363f7314b402c743fc9d31aba1f4ef40147753b7
6
+ metadata.gz: 383cde1336e59dc26217572792cd1f01cfa75713f621d87c4318edc35685a1a22ea528bc803d9897b74bb89ac2cda92428ecaed4ef5174499c2fc4904dff9be7
7
+ data.tar.gz: 42c8511976b95d1b078fbfc4885fb47ddfc4b320e5c3888940d6f74dc8be821fa1cacc90f7add020b6fa9aefc98f6d54f8a683b97636809ee620bbfa4f67425c
data/README.md CHANGED
@@ -537,6 +537,30 @@ 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
+ #### Other useful methods
541
+
542
+ In case you need the time stamp, we added the method `stamp` to the `Time` class
543
+
544
+ ```ruby
545
+ puts Time.now.stamp
546
+ #> 2019-01-02T11:03:23.000Z
547
+ ```
548
+
549
+ In class `Date` we added a very handy `random` method you can use to generate random dates.
550
+
551
+ ```ruby
552
+ # random date from today to 60 days after
553
+ puts Date.today.random(60)
554
+
555
+ # random date from 01-09-2005 to 100 days later
556
+ puts Date.strptime('01-09-2005', '%d-%m-%Y').random(100)
557
+
558
+ # random date from 2003/10/31 to today
559
+ puts Date.new(2003,10,31).random(Date.today)
560
+ ```
561
+
562
+
563
+
540
564
  ## Contributing
541
565
 
542
566
  Bug reports and pull requests are welcome on GitHub at https://github.com/marioruiz/nice_hash.
@@ -92,6 +92,39 @@ class Array
92
92
  end
93
93
  end
94
94
 
95
+ require 'date'
96
+ class Date
97
+ ###########################################################################
98
+ # It will generate a random date
99
+ # In case days is a Date it will generate until that date
100
+ # In case days is an Integer it will generate from the self date + the number of days specified
101
+ # examples:
102
+ # puts Date.today.random(60) # random date from today to 60 days after
103
+ # puts Date.strptime('01-09-2005', '%d-%m-%Y').random(100)
104
+ # puts Date.new(2003,10,31).random(Date.today) #Random date from 2003/10/31 to today
105
+ ###########################################################################
106
+ def random(days)
107
+ if days.kind_of?(Date) then
108
+ dif_dates = self - (days+1)
109
+ date_result = self + rand(dif_dates)
110
+ return date_result
111
+ elsif days.kind_of?(Integer) then
112
+ date_result = self + rand(days+1)
113
+ return date_result
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+
120
+ class Time
121
+ # It will return in the format: '%Y-%m-%dT%H:%M:%S.000Z'
122
+ # Example: puts Time.now.stamp
123
+ def stamp
124
+ return self.strftime('%Y-%m-%dT%H:%M:%S.000Z')
125
+ end
126
+ end
127
+
95
128
  class Hash
96
129
  ###########################################################################
97
130
  # Returns the value of the key specified in case doesn't exist a Hash method with the same name
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.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz