hash_walker 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/hash_walker.gemspec +2 -2
- data/lib/hash_walker/core_extensions/hash.rb +5 -0
- data/spec/hash_walker/hash_walker_spec.rb +2 -10
- metadata +5 -3
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![Build
|
4
4
|
Status](https://secure.travis-ci.org/lloydmeta/hash_walker.png)](http://travis-ci.org/lloydmeta/hash_walker)
|
5
5
|
|
6
|
-
A simple gem that allows you to traverse/walk a Hash (perhaps obtained from doing JSON::parse on a JSON string) according to a set of keys (also a hash), passing in a block to perform actions. This method will yield your block with each value found and the Hash 'path' of the value as arguments.
|
6
|
+
A simple gem that allows you to traverse/walk a Hash (perhaps obtained from doing JSON::parse on a JSON string) according to a set of keys (also a hash), passing in a block to perform actions. This method will yield your block with each value found and the Hash 'path' of the value (as an array) as arguments.
|
7
7
|
|
8
8
|
__Note__ This gem was built on Ruby 1.9.3, but Travis testing tells me its 1.9.2 compatible as well. Your mileage may vary...
|
9
9
|
|
data/hash_walker.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = %q{hash_walker}
|
3
|
-
gem.version = "0.0.
|
3
|
+
gem.version = "0.0.4"
|
4
4
|
gem.date = %q{2012-09-30}
|
5
5
|
gem.authors = ["Lloyd Meta"]
|
6
6
|
gem.email = ["lloydmeta@gmail.com"]
|
7
7
|
gem.homepage = "http://github.com/lloydmeta/hash_walker"
|
8
|
-
gem.description = %q{A simple gem that allows you to traverse/walk a Hash according to a set of keys (also a hash), passing in a block to perform actions. This method will yield your block with each value found and the Hash 'path' of the value as arguments}
|
8
|
+
gem.description = %q{A simple gem that allows you to traverse/walk a Hash according to a set of keys (also a hash), passing in a block to perform actions. This method will yield your block with each value found and the Hash 'path' of the value (as an array) as arguments}
|
9
9
|
gem.summary = gem.description
|
10
10
|
|
11
11
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -10,6 +10,11 @@ module HashWalker
|
|
10
10
|
Float
|
11
11
|
]
|
12
12
|
|
13
|
+
# Walks/traveres the current Hash object according to a set of
|
14
|
+
# keys (itself also an array/hash)
|
15
|
+
# Params:
|
16
|
+
# +keys+:: +Array+ An array of keys (which themselves can be hashes and further arrays) to look for
|
17
|
+
# +&block+:: +Block+ object that gets yielded and passed each value and each path (array) respectively as arguments
|
13
18
|
def each_primitive_value_at(keys, path = [], &block)
|
14
19
|
keys.each do |key|
|
15
20
|
if key.is_a?(Hash)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Hash do
|
4
|
-
context '
|
4
|
+
context 'simple example' do
|
5
5
|
subject do
|
6
6
|
{
|
7
7
|
"a_array" => [1,2,3,4,5],
|
@@ -508,18 +508,10 @@ describe Hash do
|
|
508
508
|
end.should_not raise_error
|
509
509
|
end
|
510
510
|
|
511
|
-
it 'should return me values with proper paths' do
|
511
|
+
it 'should return me proper values with proper paths ' do
|
512
512
|
values_and_paths_found = []
|
513
513
|
|
514
514
|
subject.each_primitive_value_at(@keys_to_read){|value, path_array|
|
515
|
-
path_as_string = path_array.reduce('') {|path_so_far, path_array_element|
|
516
|
-
if path_array_element.is_a?(String)
|
517
|
-
path_so_far += %Q~["#{path_array_element}"]~
|
518
|
-
elsif path_array_element.is_a?(Integer)
|
519
|
-
path_so_far += %Q~[#{path_array_element.to_s}]~
|
520
|
-
end
|
521
|
-
path_so_far
|
522
|
-
}
|
523
515
|
values_and_paths_found << [value, path_array]
|
524
516
|
}
|
525
517
|
values_and_paths_found.size.should eq(47)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_walker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,8 @@ date: 2012-09-30 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
14
14
|
description: A simple gem that allows you to traverse/walk a Hash according to a set
|
15
15
|
of keys (also a hash), passing in a block to perform actions. This method will yield
|
16
|
-
your block with each value found and the Hash 'path' of the value as
|
16
|
+
your block with each value found and the Hash 'path' of the value (as an array)
|
17
|
+
as arguments
|
17
18
|
email:
|
18
19
|
- lloydmeta@gmail.com
|
19
20
|
executables: []
|
@@ -56,7 +57,8 @@ signing_key:
|
|
56
57
|
specification_version: 3
|
57
58
|
summary: A simple gem that allows you to traverse/walk a Hash according to a set of
|
58
59
|
keys (also a hash), passing in a block to perform actions. This method will yield
|
59
|
-
your block with each value found and the Hash 'path' of the value as
|
60
|
+
your block with each value found and the Hash 'path' of the value (as an array)
|
61
|
+
as arguments
|
60
62
|
test_files:
|
61
63
|
- spec/hash_walker/hash_walker_spec.rb
|
62
64
|
- spec/spec_helper.rb
|