jsonpath 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +12 -6
- data/VERSION +1 -1
- data/jsonpath.gemspec +2 -2
- data/lib/jsonpath.rb +29 -11
- data/lib/jsonpath/enumerable.rb +3 -2
- data/spec/jsonpath_spec.rb +5 -0
- metadata +3 -3
data/Rakefile
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'rake/testtask'
|
2
2
|
|
3
|
+
#desc "Build it up"
|
4
|
+
#task :build do
|
5
|
+
# sh "rex --independent -o lib/jsonpath/grammar.rex.rb lib/grammar/grammar.rex"
|
6
|
+
# sh "racc -v -O parser.output -o lib/jsonpath/grammar.y.rb lib/grammar/grammar.y"
|
7
|
+
#end
|
8
|
+
|
3
9
|
begin
|
4
10
|
require 'jeweler'
|
5
11
|
Jeweler::Tasks.new do |s|
|
@@ -34,9 +40,9 @@ Spec::Rake::SpecTask.new do |t|
|
|
34
40
|
t.spec_files = FileList['spec/*.rb']
|
35
41
|
end
|
36
42
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
require 'rake/testtask'
|
44
|
+
Rake::TestTask.new(:test) do |test|
|
45
|
+
test.libs << 'lib' << 'test'
|
46
|
+
test.pattern = 'test/**/*_test.rb'
|
47
|
+
test.verbose = true
|
48
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/jsonpath.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{jsonpath}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joshua Hull"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-04-27}
|
13
13
|
s.description = %q{Ruby implementation of http://goessner.net/articles/JsonPath/}
|
14
14
|
s.email = %q{joshbuddy@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/jsonpath.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'strscan'
|
2
|
-
|
3
|
-
|
4
|
-
$LOAD_PATH.add_current
|
2
|
+
$LOAD_PATH << File.expand_path(File.basename(__FILE__))
|
5
3
|
|
6
4
|
require File.join('jsonpath', 'enumerable')
|
7
5
|
|
@@ -14,15 +12,35 @@ class JsonPath
|
|
14
12
|
@path = []
|
15
13
|
bracket_count = 0
|
16
14
|
while not scanner.eos?
|
17
|
-
token = scanner.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
if token = scanner.scan(/\$/)
|
16
|
+
@path << token
|
17
|
+
elsif token = scanner.scan(/@/)
|
18
|
+
@path << token
|
19
|
+
elsif token = scanner.scan(/[a-zA-Z]+/)
|
22
20
|
@path << "['#{token}']"
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
elsif token = scanner.scan(/'(.*?)'/)
|
22
|
+
@path << "[#{token}]"
|
23
|
+
elsif token = scanner.scan(/\[/)
|
24
|
+
count = 1
|
25
|
+
while !count.zero?
|
26
|
+
if t = scanner.scan(/\[/)
|
27
|
+
token << t
|
28
|
+
count += 1
|
29
|
+
elsif t = scanner.scan(/\]/)
|
30
|
+
token << t
|
31
|
+
count -= 1
|
32
|
+
elsif t = scanner.scan(/[^\[\]]*/)
|
33
|
+
token << t
|
34
|
+
end
|
35
|
+
end
|
36
|
+
@path << token
|
37
|
+
elsif token = scanner.scan(/\.\./)
|
38
|
+
@path << token
|
39
|
+
elsif scanner.scan(/\./)
|
40
|
+
elsif token = scanner.scan(/\*/)
|
41
|
+
@path << token
|
42
|
+
elsif token = scanner.scan(/./)
|
43
|
+
@path.last << token
|
26
44
|
end
|
27
45
|
end
|
28
46
|
end
|
data/lib/jsonpath/enumerable.rb
CHANGED
@@ -12,7 +12,7 @@ class JsonPath
|
|
12
12
|
else
|
13
13
|
case expr = @path[pos]
|
14
14
|
when '*', '..'
|
15
|
-
each(node, pos + 1, &blk)
|
15
|
+
each(node, pos + 1, &blk)
|
16
16
|
when '$'
|
17
17
|
each(node, pos + 1, &blk) if node == @object
|
18
18
|
when '@'
|
@@ -42,7 +42,8 @@ class JsonPath
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
else
|
45
|
-
|
45
|
+
#p "#{node.inspect} ---> node #{@path[pos]}"
|
46
|
+
blk.call(node) if pos == (@path.size - 1) && node && eval("node #{@path[pos]}")
|
46
47
|
end
|
47
48
|
|
48
49
|
if pos > 0 && @path[pos-1] == '..'
|
data/spec/jsonpath_spec.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joshua Hull
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-27 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|