json_wrapper 0.1.1 → 0.1.2
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/json_wrapper.rb +13 -0
- data/lib/json_wrapper/version.rb +1 -1
- 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: a6a31f9ff5c7915286bd0453e7e0980406684368
|
4
|
+
data.tar.gz: a56e9fd415c2ce4a55917f8c26191b9f6752d65a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f6a059093af76db7dc09c70c1e1f6546c0e92668d260f4dff1792a6b158455b2351ce69e81a7f0ec5605a39fd9d1011d67d1e7296ff1e2a61b39a8e078491b3
|
7
|
+
data.tar.gz: 1d21f0938fb243d5c93f2f654323cef976f916bac9729f7ca9f380a3c53ea4e64ba2aa130fe40cea9a113464a39cd380de47a82dde08d40f52c5596f322527c0
|
data/lib/json_wrapper.rb
CHANGED
@@ -115,11 +115,24 @@ class JsonWrapper
|
|
115
115
|
# @return [JsonWrapper] JsonWrapper of the value
|
116
116
|
def get(key)
|
117
117
|
return JsonWrapper.new(value[key]) if array? and key.kind_of?(Fixnum)
|
118
|
+
return JsonWrapper.new(value[key.to_i]) if array? and key.kind_of?(String)
|
119
|
+
return JsonWrapper.new(value[key.to_s.to_i]) if array? and key.kind_of?(Symbol)
|
118
120
|
return JsonWrapper.new(value[key]) if hash? and key.kind_of?(String)
|
119
121
|
return JsonWrapper.new(value[key.to_s]) if hash? and key.kind_of?(Symbol)
|
120
122
|
JsonWrapper.new
|
121
123
|
end
|
122
124
|
|
125
|
+
# Try to get value by chained call of keys
|
126
|
+
# @param key [Array] array of keys, can be String or Fixnum
|
127
|
+
# @return [JsonWrapper] JsonWrapper of the value
|
128
|
+
def resolve_chain(*keys)
|
129
|
+
target = self
|
130
|
+
keys.flatten.each do |key|
|
131
|
+
target = target[key]
|
132
|
+
end
|
133
|
+
target
|
134
|
+
end
|
135
|
+
|
123
136
|
# @see #get
|
124
137
|
def [](key)
|
125
138
|
get(key)
|
data/lib/json_wrapper/version.rb
CHANGED