hash_util 1.4 → 1.5
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/hash_helper.rb +0 -10
- data/lib/hash_util/version.rb +1 -1
- data/lib/hash_util.rb +17 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99882ba227b97ceb88ea95b2d040cfe01c13cc38
|
4
|
+
data.tar.gz: f6345a849bc2d9bec00a3b920a1bdb5a864fb181
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bbd8f603ad7f42db8444d9c6ef106a09097ff3a28e0e36537c31557b11c2a86c3f9560fe34105d28d800e40528bfa88e485a5dba2a4dc82857b9f822fedae65
|
7
|
+
data.tar.gz: 2e54a6c67dca6ab6bb11c0f3a398ecfb178f1541de4aae21e67e6c296f9f815eadd9051d17e3984472c54ec4d059fc3da492bef0e3ed22b32340fdf6657bd219
|
data/lib/hash_helper.rb
CHANGED
@@ -9,16 +9,6 @@ module HashHelper
|
|
9
9
|
str.scan(/[0-9.e-]+|\w+/)
|
10
10
|
end
|
11
11
|
|
12
|
-
# extracts all numbers in a hash string
|
13
|
-
def extract_numbers_hash(str)
|
14
|
-
str = tokenize str
|
15
|
-
# extract all nums including those using e notation
|
16
|
-
str.select! { |m| /^[0-9.e-]+$/.match m }
|
17
|
-
# used Float instead of to_f as to_f converts string to '0'
|
18
|
-
str.collect do |m|
|
19
|
-
Float m
|
20
|
-
end
|
21
|
-
end
|
22
12
|
|
23
13
|
# submethod used by add_hash2_to_hash1 if type Array
|
24
14
|
def add_hash_if_array(a1, b1)
|
data/lib/hash_util/version.rb
CHANGED
data/lib/hash_util.rb
CHANGED
@@ -9,6 +9,7 @@ module HashUtil
|
|
9
9
|
# adds hash2 value to hash1 value recursively
|
10
10
|
# alternate implementation using a string instead of hash
|
11
11
|
# can be found in hash helper module
|
12
|
+
|
12
13
|
def self.add_hash2_to_hash1(a1, b1)
|
13
14
|
if a1.class.name == 'Array'
|
14
15
|
add_hash_if_array(a1, b1)
|
@@ -19,12 +20,14 @@ module HashUtil
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
23
|
+
|
22
24
|
# set all values in the hash to 0
|
23
25
|
# This method should be moved to helper module and
|
24
26
|
# another genericmethod called set_Values to be added
|
25
27
|
# that can set all values including zero
|
26
28
|
# TODO optimize
|
27
29
|
# FIXME rubocop
|
30
|
+
|
28
31
|
def self.zero(obj)
|
29
32
|
if obj.class.name == 'Array'
|
30
33
|
obj = obj.collect do |m|
|
@@ -43,10 +46,12 @@ module HashUtil
|
|
43
46
|
end
|
44
47
|
end
|
45
48
|
|
49
|
+
|
46
50
|
# copies values from a hash string in to another
|
47
51
|
# The 2 hashes should be of same structure but keys
|
48
52
|
# can be different
|
49
53
|
# FIXME rubocop
|
54
|
+
|
50
55
|
def self.merge(hash_str1, hash_str2)
|
51
56
|
# extract nums, words
|
52
57
|
token1 = hash_str1.scan(/[[+-]?([0-9]*[.])?[0-9e-]+]+|\w+|[{}\[\]:,"\040]/)
|
@@ -63,4 +68,16 @@ module HashUtil
|
|
63
68
|
end
|
64
69
|
token1.join.gsub(/\s+/, ' ')
|
65
70
|
end
|
71
|
+
|
72
|
+
|
73
|
+
# extracts all numbers in a hash string
|
74
|
+
def self.extract_numbers_hash(str)
|
75
|
+
str = tokenize str
|
76
|
+
# extract all nums including those using e notation
|
77
|
+
str.select! { |m| /^[0-9.e-]+$/.match m }
|
78
|
+
# used Float instead of to_f as to_f converts string to '0'
|
79
|
+
str.collect do |m|
|
80
|
+
Float m
|
81
|
+
end
|
82
|
+
end
|
66
83
|
end
|