json_wrapper 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28dd99f95fe890b74342619c48b11462ef23203f
4
- data.tar.gz: 97689c5402df83cc1ca53f13faabbf9937761d94
3
+ metadata.gz: a6a31f9ff5c7915286bd0453e7e0980406684368
4
+ data.tar.gz: a56e9fd415c2ce4a55917f8c26191b9f6752d65a
5
5
  SHA512:
6
- metadata.gz: 394045c245b02e1db78826a23d116e4dca53eed2a9771940eb500190eba783694bae727dc4c2cc8092817d6bc119d91bd541920ec70d0ad5da21ef514c37043e
7
- data.tar.gz: b9d7923e0b587a96f6c9796eb2ac6df72eb9dec5c81c3a42e641adc7d6e8b5dea2cd68b3b12b06fa35bc52ca5f1c019c0ec3083b2f672aabd03784ad7df95acb
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)
@@ -1,5 +1,5 @@
1
1
  #encoding: utf-8
2
2
 
3
3
  class JsonWrapper
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Guo