nice_hash 1.18.5 → 1.18.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/nice/hash/add_to_ruby.rb +20 -18
- data/lib/nice_hash.rb +1 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c8cb3e741e17cf400b34bc3a31ec874fb030466b2f56431f0ec5aa79e37af7f
|
4
|
+
data.tar.gz: f023c96b5a5768bac968765032c782d1d01e9705f778748903fb75a0b91d582e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 448740fdbc4843c705ac79d5d33ba6fcfdf453e7ff76d1a0cf77fa2a648c37ca99d441fcef8378030e2de77a100d907832e216938948c9f3b8ebba3e8ef75b8a
|
7
|
+
data.tar.gz: 6d3acf6139d0612d7d3ae45b5fec8ca19ba66262f9b4f6b71c26e66c4ca1df68f60a7d6f120307e267d06752d3db3fec43265e82004bf1ef9143ec4ea89531ed
|
data/README.md
CHANGED
@@ -171,6 +171,15 @@ Also if you have a JSON string you want to parse it and get the values of certai
|
|
171
171
|
#> {:name=>["Peter Smith", ["myFavor1", "Special ticket"]], :idt=>[345, 3123, 3145]}
|
172
172
|
```
|
173
173
|
|
174
|
+
To make easier to compare values by default it is setup SP_COMPARE_NUMBERS_AS_STRINGS = true, that will return true for example in these comparations:
|
175
|
+
* '300' == 300
|
176
|
+
* '300.12' == 300.12
|
177
|
+
* "" == nil
|
178
|
+
|
179
|
+
To avoid that set SP_COMPARE_NUMBERS_AS_STRINGS = false before `require 'nice_hash'`
|
180
|
+
Take in consideration certain libraries (fex 'net/ldap') are failing if `SP_COMPARE_NUMBERS_AS_STRINGS` is set to true. Since NiceHash is modifying the String class.
|
181
|
+
|
182
|
+
|
174
183
|
### How to access the different keys
|
175
184
|
|
176
185
|
You can access the keys of the hash like always, but now we added to the Hash class the posibility of accessing it using:
|
@@ -1,18 +1,20 @@
|
|
1
1
|
class String
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
2
|
+
|
3
|
+
if SP_COMPARE_NUMBERS_AS_STRINGS
|
4
|
+
###########################################################################
|
5
|
+
# When comparing an string and an integer, float or nil, it will be automatically converted to string:
|
6
|
+
# "300" == 300 #will return true
|
7
|
+
# 200.1=="200.1" #will return true
|
8
|
+
# ""==nil #will return true
|
9
|
+
###########################################################################
|
10
|
+
def ==(par)
|
11
|
+
if par.is_a?(Integer) || par.nil? || par.is_a?(Float)
|
12
|
+
super(par.to_s)
|
13
|
+
else
|
14
|
+
super(par)
|
15
|
+
end
|
13
16
|
end
|
14
17
|
end
|
15
|
-
|
16
18
|
###########################################################################
|
17
19
|
# In case the string is a json it will return the keys specified. the keys need to be provided as symbols.
|
18
20
|
# In case the string is not a json then it will notify the error and return empty Hash
|
@@ -114,8 +116,8 @@ class Array
|
|
114
116
|
###########################################################################
|
115
117
|
def deep_copy
|
116
118
|
NiceHash.deep_clone(self)
|
117
|
-
end
|
118
|
-
|
119
|
+
end
|
120
|
+
|
119
121
|
alias nice_copy deep_copy
|
120
122
|
end
|
121
123
|
|
@@ -207,7 +209,7 @@ class Hash
|
|
207
209
|
###########################################################################
|
208
210
|
def deep_copy
|
209
211
|
NiceHash.deep_clone(self)
|
210
|
-
end
|
212
|
+
end
|
211
213
|
|
212
214
|
###########################################################################
|
213
215
|
# It will filter the hash by the key specified on select_hash_key.
|
@@ -280,7 +282,7 @@ class Hash
|
|
280
282
|
|
281
283
|
###########################################################################
|
282
284
|
# Search if the hash contains the supplied key
|
283
|
-
# search can be a string, symbol or regexp.
|
285
|
+
# search can be a string, symbol or regexp.
|
284
286
|
# In case of string or symbol it will return true even if only part of the key fits the 'search'
|
285
287
|
###########################################################################
|
286
288
|
def has_rkey?(search)
|
@@ -345,14 +347,14 @@ class Object
|
|
345
347
|
end
|
346
348
|
self
|
347
349
|
end
|
348
|
-
|
350
|
+
|
349
351
|
###########################################################################
|
350
352
|
# include? but the opposite. Check if the object is included on the array
|
351
353
|
###########################################################################
|
352
354
|
def in?(array)
|
353
355
|
array.include?(self)
|
354
356
|
end
|
355
|
-
|
357
|
+
|
356
358
|
end
|
357
359
|
|
358
360
|
class Array
|
data/lib/nice_hash.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
SP_ADD_TO_RUBY = true if !defined?(SP_ADD_TO_RUBY)
|
2
|
-
|
2
|
+
SP_COMPARE_NUMBERS_AS_STRINGS = true if !defined?(SP_COMPARE_NUMBERS_AS_STRINGS)
|
3
3
|
|
4
4
|
require_relative "nice/hash/add_to_ruby" if SP_ADD_TO_RUBY
|
5
5
|
require_relative "nice/hash/change_one_by_one"
|
@@ -18,7 +18,6 @@ require_relative "nice/hash/transtring"
|
|
18
18
|
require_relative "nice/hash/validate"
|
19
19
|
require_relative "nice/hash/deep_clone"
|
20
20
|
|
21
|
-
|
22
21
|
require "string_pattern"
|
23
22
|
|
24
23
|
###########################################################################
|
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.18.
|
4
|
+
version: 1.18.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string_pattern
|
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
|
-
rubygems_version: 3.4.
|
105
|
+
rubygems_version: 3.4.19
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: NiceHash creates hashes following certain patterns so your testing will be
|