nice_hash 1.7.2 → 1.7.3
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/lib/nice/hash/add_to_ruby.rb +19 -16
- 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: 7f7cbf721773e1bd115612af19975990b234392a560d49ead605f3ac67239fdf
|
|
4
|
+
data.tar.gz: b4ebd76c70c8f84e714452625028a7a543fb60ceb88a9e67333d19408447109d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed7d54477160dde0a4ab650e4f722142833671ac73920f3b44e3b9aa7f09867e567cb36fc73a5a1fe10f348371416cfabdca20b6e53d817a64d63ae0f055c069
|
|
7
|
+
data.tar.gz: 2140c266043b1bcaed1b381c52e201f4c2351ff4dfdc0e386d8a7dc5a8f0954ce8637dbd635ee9a05ab51997ad485150b7c0b6d23945d18543faec0b4f0ba7b4
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
class String
|
|
2
|
-
|
|
3
2
|
###########################################################################
|
|
4
3
|
# When comparing an string and an integer, float or nil, it will be automatically converted to string:
|
|
5
4
|
# "300" == 300 #will return true
|
|
@@ -7,27 +6,30 @@ class String
|
|
|
7
6
|
# ""==nil #will return true
|
|
8
7
|
###########################################################################
|
|
9
8
|
def ==(par)
|
|
10
|
-
if par.
|
|
11
|
-
super(par.to_s
|
|
9
|
+
if par.is_a?(Integer) || par.nil? || par.is_a?(Float)
|
|
10
|
+
super(par.to_s)
|
|
12
11
|
else
|
|
13
12
|
super(par)
|
|
14
13
|
end
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
###########################################################################
|
|
18
|
-
# In case the string is a json it will return the keys specified. the keys need to be provided as symbols
|
|
17
|
+
# In case the string is a json it will return the keys specified. the keys need to be provided as symbols.
|
|
18
|
+
# In case the string is not a json then it will notify the error and return empty Hash
|
|
19
19
|
# input:
|
|
20
20
|
# keys:
|
|
21
21
|
# 1 value with key or an array of keys
|
|
22
22
|
# In case the key supplied doesn't exist in the hash then it will be returned nil for that one
|
|
23
23
|
# output:
|
|
24
|
-
# if keys given: a hash of (keys, values) or the value, if the key is found more than once in the json string, then it will be return a hash op arrays
|
|
25
|
-
# if no keys given
|
|
24
|
+
# if keys given: a hash of (keys, values) or the value, if the key is found more than once in the json string, then it will be return a hash op arrays.
|
|
25
|
+
# if no keys given: the json string as a ruby structure.
|
|
26
|
+
# if no json string or wrong json string, an empty hash.
|
|
26
27
|
###########################################################################
|
|
27
28
|
def json(*keys)
|
|
28
29
|
require 'json'
|
|
29
|
-
feed_symbols = JSON.parse(self, symbolize_names: true)
|
|
30
30
|
result = {}
|
|
31
|
+
begin
|
|
32
|
+
feed_symbols = JSON.parse(self, symbolize_names: true)
|
|
31
33
|
if !keys.empty?
|
|
32
34
|
result_tmp = if keys[0].is_a?(Symbol)
|
|
33
35
|
NiceHash.get_values(feed_symbols, keys)
|
|
@@ -54,6 +56,9 @@ class String
|
|
|
54
56
|
else
|
|
55
57
|
result = feed_symbols
|
|
56
58
|
end
|
|
59
|
+
rescue StandardError => stack
|
|
60
|
+
puts stack.to_s
|
|
61
|
+
end
|
|
57
62
|
result
|
|
58
63
|
end
|
|
59
64
|
end
|
|
@@ -104,24 +109,22 @@ class Date
|
|
|
104
109
|
# puts Date.new(2003,10,31).random(Date.today) #Random date from 2003/10/31 to today
|
|
105
110
|
###########################################################################
|
|
106
111
|
def random(days)
|
|
107
|
-
if days.
|
|
108
|
-
dif_dates = self - (days+1)
|
|
112
|
+
if days.is_a?(Date)
|
|
113
|
+
dif_dates = self - (days + 1)
|
|
109
114
|
date_result = self + rand(dif_dates)
|
|
110
|
-
|
|
111
|
-
elsif days.
|
|
112
|
-
date_result = self + rand(days+1)
|
|
113
|
-
|
|
115
|
+
date_result
|
|
116
|
+
elsif days.is_a?(Integer)
|
|
117
|
+
date_result = self + rand(days + 1)
|
|
118
|
+
date_result
|
|
114
119
|
end
|
|
115
120
|
end
|
|
116
|
-
|
|
117
121
|
end
|
|
118
122
|
|
|
119
|
-
|
|
120
123
|
class Time
|
|
121
124
|
# It will return in the format: '%Y-%m-%dT%H:%M:%S.%LZ'
|
|
122
125
|
# Example: puts Time.now.stamp
|
|
123
126
|
def stamp
|
|
124
|
-
|
|
127
|
+
strftime('%Y-%m-%dT%H:%M:%S.%LZ')
|
|
125
128
|
end
|
|
126
129
|
end
|
|
127
130
|
|
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.7.
|
|
4
|
+
version: 1.7.3
|
|
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-01-
|
|
11
|
+
date: 2019-01-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: string_pattern
|