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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42e9d259e17d9b4e348851b3d543542f26e21782
4
- data.tar.gz: 71d7179641b864666b483b04501421a988a4a79e
3
+ metadata.gz: ab549485511ee94e51e5f7c31244c41fc8cc832c
4
+ data.tar.gz: 8b4e7a4bf9a56a5df26ba3d70c06585abfd1bbae
5
5
  SHA512:
6
- metadata.gz: aedbe6dad81938ffaaf61e065bc82fa309228fb3f8591d90a2424c4957c5299b9c6bb5d6b55bcddc658a346d54d325dda562fe4104853be3526773269c49f697
7
- data.tar.gz: c806c1f383a78901e685ea305d0e7ef2ed27f079634c399dfaff3c68309bcc84f3e15c6f1838dbc89d8d4e0f2367525e7cd8e63dee9842f777bbfe1cf962cc9e
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
 
@@ -1,3 +1,3 @@
1
1
  module HashUtil
2
- VERSION = "1.2"
2
+ VERSION = "1.3"
3
3
  end
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
- if /[0-9.]/.match token1[i]
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| /[0-9.]/.match m }
75
+ str.select! { |m| /^[0-9.e-]+$/.match m }
73
76
  str.collect do |m|
74
- m.to_s.include?('.') ? m.to_f : m.to_i
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.2'
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-09-29 00:00:00.000000000 Z
11
+ date: 2017-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler