multi_hash_iterator 0.1.0 → 0.1.1
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/multi_hash_iterator.rb +3 -3
- data/multi_hash_iterator.gemspec +1 -1
- data/test/helper.rb +1 -1
- data/test/test_multihashiterator.rb +19 -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: 88ea9612ce4415bb7a612f00af4edcec6edf2a6c
|
4
|
+
data.tar.gz: 688f2342d86cad7c69f1f3ae2aeab36f4ae4cf75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b15ea5786196b6a2f58643440442fc80a91fb679aab9092d841c013b50e5aa151ba70b86ca29921b384a6035a43e47f686315e5ed79532acab7022f3795a2d28
|
7
|
+
data.tar.gz: ae72986870f7e74381a8b827bce6695afc142d936895f4ed2654ac019f5a065a9de03f0d6c47c63248b7e3e2c8e79b545d21aaa0a08e2cbcebaab1b2bf5da511
|
data/lib/multi_hash_iterator.rb
CHANGED
@@ -6,7 +6,6 @@ class MultiHash
|
|
6
6
|
|
7
7
|
def initialize *hashes
|
8
8
|
@hashes = hashes
|
9
|
-
@final_hash = {}
|
10
9
|
end
|
11
10
|
|
12
11
|
# Enumerate for each key.
|
@@ -15,10 +14,11 @@ class MultiHash
|
|
15
14
|
def each
|
16
15
|
return enum_for(:each) unless block_given?
|
17
16
|
|
17
|
+
final_hash = {}
|
18
18
|
count = @hashes.length
|
19
19
|
count.times do |i|
|
20
20
|
@hashes[i].each do |key, v|
|
21
|
-
next if
|
21
|
+
next if final_hash[key]
|
22
22
|
|
23
23
|
values = [].fill(nil, 0, i)
|
24
24
|
values << v
|
@@ -27,7 +27,7 @@ class MultiHash
|
|
27
27
|
end
|
28
28
|
|
29
29
|
yield key, values if block_given?
|
30
|
-
|
30
|
+
final_hash[key] = values
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
data/multi_hash_iterator.gemspec
CHANGED
@@ -2,7 +2,7 @@ require './lib/multi_hash_iterator'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "multi_hash_iterator"
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
s.authors = ["Albert Tedja"]
|
7
7
|
s.email = "nicho_tedja@yahoo.com"
|
8
8
|
s.homepage = "https://github.com/atedja/multi_hash_iterator"
|
data/test/helper.rb
CHANGED
@@ -28,6 +28,25 @@ class TestMultiHashIterator < Minitest::Test
|
|
28
28
|
end
|
29
29
|
|
30
30
|
|
31
|
+
def test_basic
|
32
|
+
h1 = { a: 1, b: 2, c: 3 }
|
33
|
+
h2 = { a: 2, b: 3 }
|
34
|
+
h3 = { b: 4, d: 6 }
|
35
|
+
mh = MultiHash.new(h1, h2, h3)
|
36
|
+
|
37
|
+
iteration = 0
|
38
|
+
mh.each do |k, v|
|
39
|
+
iteration += 1
|
40
|
+
end
|
41
|
+
|
42
|
+
mh.each do |k, v|
|
43
|
+
iteration += 1
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_equal 8, iteration
|
47
|
+
end
|
48
|
+
|
49
|
+
|
31
50
|
def test_compound_values
|
32
51
|
h1 = { a: 1, b: 2, c: [100, 200] }
|
33
52
|
h2 = { a: 2, b: "foo" }
|