jsonpath 0.8.3 → 0.8.4
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/jsonpath/parser.rb +4 -3
- data/lib/jsonpath/version.rb +1 -1
- data/test/test_jsonpath.rb +10 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 458f8cfb291930dcf500cb378da87a4c5ea08ada
|
4
|
+
data.tar.gz: 28cc08dea7e072cf946bd2384be4781abeb214f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32b2d7550e5676ea6b1a4403633ffe8da9fd73638ca7ec87b556ab263e05788adf78a023fb488fddb22c14733d0f504abda74c9f26890037a635864908a8e146
|
7
|
+
data.tar.gz: 35ac4056bc5d22ddc3192824d7e228f212aff357e2ae789908b7d855601c78c64a4678c188983873e173201b02c227651bdc7cca7fe86b608f53e5ce83d1d35c
|
data/lib/jsonpath/parser.rb
CHANGED
@@ -22,7 +22,7 @@ class JsonPath
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def parse_exp(exp)
|
25
|
-
exp = exp.gsub(/@/, '').gsub(/[\(\)]/, '')
|
25
|
+
exp = exp.gsub(/@/, '').gsub(/[\(\)]/, '').gsub(/"/, '\'').strip
|
26
26
|
scanner = StringScanner.new(exp)
|
27
27
|
elements = []
|
28
28
|
until scanner.eos?
|
@@ -34,9 +34,9 @@ class JsonPath
|
|
34
34
|
end
|
35
35
|
if t = scanner.scan(/\['\w+'\]+/)
|
36
36
|
elements << t.gsub(/\[|\]|'|\s+/, '')
|
37
|
-
elsif t = scanner.scan(
|
37
|
+
elsif t = scanner.scan(/(\s+)?[<>=][<>=]?(\s+)?/)
|
38
38
|
operator = t
|
39
|
-
elsif t = scanner.scan(/(\s+)?'
|
39
|
+
elsif t = scanner.scan(/(\s+)?'?.*'?(\s+)?/)
|
40
40
|
operand = t.delete("'").strip
|
41
41
|
elsif t = scanner.scan(/.*/)
|
42
42
|
raise "Could not process symbol: #{t}"
|
@@ -45,6 +45,7 @@ class JsonPath
|
|
45
45
|
el = dig(elements, @_current_node)
|
46
46
|
return false unless el
|
47
47
|
return true if operator.nil? && el
|
48
|
+
|
48
49
|
operand = operand.to_f if operand.to_i.to_s == operand || operand.to_f.to_s == operand
|
49
50
|
el.send(operator.strip, operand)
|
50
51
|
end
|
data/lib/jsonpath/version.rb
CHANGED
data/test/test_jsonpath.rb
CHANGED
@@ -257,6 +257,16 @@ class TestJsonpath < MiniTest::Unit::TestCase
|
|
257
257
|
|
258
258
|
def test_dig_return_string
|
259
259
|
assert_equal ['asdf'], JsonPath.new("$.store.book..tags[?(@ == 'asdf')]").on(@object)
|
260
|
+
assert_equal [], JsonPath.new("$.store.book..tags[?(@ == 'not_asdf')]").on(@object)
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_slash_in_value
|
264
|
+
data = {
|
265
|
+
'data' => {
|
266
|
+
'type' => 'mps/awesome'
|
267
|
+
}
|
268
|
+
}
|
269
|
+
assert_equal [{ 'type' => 'mps/awesome' }], JsonPath.new("$.data[?(@.type == \"mps/awesome\")]").on(data)
|
260
270
|
end
|
261
271
|
|
262
272
|
def example_object
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonpath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hull
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-06-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
version: '0'
|
144
144
|
requirements: []
|
145
145
|
rubyforge_project: jsonpath
|
146
|
-
rubygems_version: 2.
|
146
|
+
rubygems_version: 2.6.10
|
147
147
|
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: Ruby implementation of http://goessner.net/articles/JsonPath/
|