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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nice/hash/add_to_ruby.rb +19 -16
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca2e46d83db5670d75aaa49bd27db09582fc21e352da61f113876463423e9e6e
4
- data.tar.gz: 58f44015c8d57cad37d45cfeb2b59d38554970b03b77f1fdac13e1d6da29b48a
3
+ metadata.gz: 7f7cbf721773e1bd115612af19975990b234392a560d49ead605f3ac67239fdf
4
+ data.tar.gz: b4ebd76c70c8f84e714452625028a7a543fb60ceb88a9e67333d19408447109d
5
5
  SHA512:
6
- metadata.gz: f87bc40c9cec0ae0d0d2ee16dcf7e862b4485ea10fa577e6fefb10a4e49f054f06ba21372f3edd6d7ad35ddffad840b690cd0d9e806cc57ce370733433b1722a
7
- data.tar.gz: ec79b4f17bb94db3e1b43efb0e60ac9e3f9cdb6d69863b1e8432034dd62e8b9d99297469c0a2912a83036f3f589887ca8ec6c3c60131bc73e6b8410588ae6094
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.kind_of?(Integer) or par.nil? or par.kind_of?(Float) then
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, an empty hash
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.kind_of?(Date) then
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
- return date_result
111
- elsif days.kind_of?(Integer) then
112
- date_result = self + rand(days+1)
113
- return date_result
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
- return self.strftime('%Y-%m-%dT%H:%M:%S.%LZ')
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.2
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-10 00:00:00.000000000 Z
11
+ date: 2019-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string_pattern