hash_path 0.1.0 → 0.2.0
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.
- data/lib/hash_path/version.rb +1 -1
- data/lib/hash_path.rb +5 -4
- metadata +2 -2
data/lib/hash_path/version.rb
CHANGED
data/lib/hash_path.rb
CHANGED
|
@@ -13,7 +13,7 @@ module HashPath
|
|
|
13
13
|
current_value = self
|
|
14
14
|
|
|
15
15
|
path_keys.each do |key|
|
|
16
|
-
return nil unless
|
|
16
|
+
return nil unless current_value.respond_to?(:[])
|
|
17
17
|
current_value = current_value[key]
|
|
18
18
|
end
|
|
19
19
|
current_value
|
|
@@ -22,17 +22,18 @@ module HashPath
|
|
|
22
22
|
# Same as at_path but raises when a path is not found
|
|
23
23
|
# The raise will give a delimited path of where the path went dead
|
|
24
24
|
# @example
|
|
25
|
-
# f = { 'foo' => {'bar' => {'baz' => 'hai'} } }
|
|
25
|
+
# f = { 'foo' => {'bar' => {'baz' => 'hai'}, "baz" => [1,2] } }
|
|
26
26
|
# f.at_path!('foo.not.baz') # Raises, message == 'foo.not'
|
|
27
27
|
# f.at_path!('not.here.yo') # Raises, message == 'not'
|
|
28
28
|
# f.at_path!('foo.bar.not') # Raises, message == 'foo.bar.not'
|
|
29
|
+
# f.at_path!("baz.1") # => 2
|
|
29
30
|
# @see HashPath#at_path
|
|
30
31
|
def at_path!(path)
|
|
31
32
|
path_keys = normalize_path(path)
|
|
32
33
|
the_keys, current_value = [], self
|
|
33
34
|
|
|
34
35
|
path_keys.each do |key|
|
|
35
|
-
raise(PathNotFound, the_keys.join(DELIMITER))unless
|
|
36
|
+
raise(PathNotFound, the_keys.join(DELIMITER)) unless current_value.respond_to?(:[])
|
|
36
37
|
the_keys << key
|
|
37
38
|
current_value = current_value[key]
|
|
38
39
|
end
|
|
@@ -46,7 +47,7 @@ module HashPath
|
|
|
46
47
|
path
|
|
47
48
|
when String, Symbol
|
|
48
49
|
path.to_s.split(DELIMITER)
|
|
49
|
-
end
|
|
50
|
+
end.map{|key| key =~ /^\d+$/ ? key.to_i : key }
|
|
50
51
|
end
|
|
51
52
|
end
|
|
52
53
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hash_path
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-
|
|
12
|
+
date: 2012-08-21 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: Easy path navigation for hashes
|
|
15
15
|
email:
|