hash_util 1.2 → 1.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/README.md +10 -7
- data/lib/hash_util/version.rb +1 -1
- data/lib/hash_util.rb +6 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab549485511ee94e51e5f7c31244c41fc8cc832c
|
4
|
+
data.tar.gz: 8b4e7a4bf9a56a5df26ba3d70c06585abfd1bbae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dab8bdaf0d4c2f5fa8abd9b5588dcb6da870901d5bcfb564d7269ebbf972470708d449733e43e3f9c5c6e1d8074db216572d7c32dd2516eeb656f897c0515d34
|
7
|
+
data.tar.gz: 7985b1064ccaf3f848367893ff32108e8863c466a2c3ca33c71f7616c5f3e7e7aa0edf3e1bb43359a16d187e8763aece87bbdeda51684320f629163de1e03e3e
|
data/README.md
CHANGED
@@ -13,6 +13,9 @@ should be of same structure
|
|
13
13
|
|
14
14
|
5) extract_numbers_hash => extracts numbers from a hash
|
15
15
|
|
16
|
+
* works with new hash syntax
|
17
|
+
|
18
|
+
* Works with hashes that have numbers as values
|
16
19
|
|
17
20
|
## Installation
|
18
21
|
|
@@ -46,13 +49,13 @@ HashUtil.zero(hash1) #{a:0,b:0,c:[0,0],d:{a:0}}
|
|
46
49
|
(3) merge
|
47
50
|
```ruby
|
48
51
|
str1 = %{
|
49
|
-
{ "OccExp": [ -0.0004, 0.09600, 0.0000, -0.0204, 0.09 ,"abc":{"a":1,"b":0,"c":[0,1,2]} ],
|
52
|
+
{ "OccExp": [ -0.0004, 0.09600, 0.0000, -0.0204, 0.09 ,"abc":{"a":1,"b":0,"c":[0,1,2]} ],
|
50
53
|
"PremRV": [ 8.500, 4.19999981, 5.0, 7.80 ]}
|
51
54
|
}
|
52
|
-
|
55
|
+
|
53
56
|
str2 = %{
|
54
57
|
{ "OccExp": [ 0.0250000004, 0.0, 0.023, 0.0250000004, 0.0280000009,
|
55
|
-
"abc":{"a":1,"b":0,"c":[0,1,2]} ], "PremRV": [ 8.5, 4.19999981, 5.5,
|
58
|
+
"abc":{"a":1,"b":0,"c":[0,1,2]} ], "PremRV": [ 8.5, 4.19999981, 5.5,
|
56
59
|
7.80000019 ]}
|
57
60
|
}
|
58
61
|
str1 = HashUtil.merge(str1,str2) # values in str1 == str2
|
@@ -61,16 +64,16 @@ HashUtil.zero(hash1) #{a:0,b:0,c:[0,0],d:{a:0}}
|
|
61
64
|
```ruby
|
62
65
|
str2 = %{
|
63
66
|
{ "OccExp": [ 0.0250000004, 0.0199999996, "abc":{"a":1,"b":0,"c":[0,1,2]}]}
|
64
|
-
}
|
67
|
+
}
|
65
68
|
HashUtil.extract_numbers_hash(str2) #[ 0.0250000004, 0.0199999996,1,0,0,1,2]
|
66
69
|
```
|
67
|
-
(5) extract_numbers_hash
|
70
|
+
(5) extract_numbers_hash
|
68
71
|
```ruby
|
69
72
|
str2 = %{
|
70
73
|
{ "OccExp": [ 0.0250000004, 0.0199999996, "abc":{"a":1,"b":0,"c":[0,1,2]}]}
|
71
|
-
}
|
74
|
+
}
|
72
75
|
HashUtil.extract_numbers_hash(str2) #[ 0.0250000004, 0.0199999996,1,0,0,1,2]
|
73
|
-
|
76
|
+
|
74
77
|
```
|
75
78
|
|
76
79
|
|
data/lib/hash_util/version.rb
CHANGED
data/lib/hash_util.rb
CHANGED
@@ -52,11 +52,14 @@ module HashUtil
|
|
52
52
|
def self.merge(hash_str1, hash_str2)
|
53
53
|
token1 = hash_str1.scan(/[[+-]?([0-9]*[.])?[0-9e-]+]+|\w+|[{}\[\]:,"\040]/)
|
54
54
|
token2 = extract_numbers_hash(hash_str2)
|
55
|
+
# byebug
|
55
56
|
j = 0
|
56
57
|
token1.each_index do |i|
|
57
|
-
|
58
|
+
begin
|
59
|
+
Float token1[i]
|
58
60
|
token1[i] = token2[j]
|
59
61
|
j += 1
|
62
|
+
rescue
|
60
63
|
end
|
61
64
|
end
|
62
65
|
token1.join.gsub(/\s+/, ' ')
|
@@ -69,9 +72,9 @@ module HashUtil
|
|
69
72
|
# extracts all numbers in a hash string
|
70
73
|
def self.extract_numbers_hash(str)
|
71
74
|
str = tokenize str
|
72
|
-
str.select! { |m|
|
75
|
+
str.select! { |m| /^[0-9.e-]+$/.match m }
|
73
76
|
str.collect do |m|
|
74
|
-
|
77
|
+
Float m
|
75
78
|
end
|
76
79
|
end
|
77
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dinesh.theetla@gmail.com
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|