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 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
- #require 'rake/testtask'
38
- #Rake::TestTask.new(:test) do |test|
39
- # test.libs << 'lib' << 'test'
40
- # test.pattern = 'test/**/*_test.rb'
41
- # test.verbose = true
42
- #end
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.0
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.0"
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-03-27}
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
- require 'load_path_find'
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.scan_until(/($|\$|@|[a-zA-Z]+|\[.*?\]|\.\.|\.(?!\.))/)
18
- case token
19
- when '.'
20
- # do nothing
21
- when /^[a-zA-Z]+$/
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
- else
24
- bracket_count == 0 && @path << token or @path[-1] += token
25
- bracket_count += token.count('[') - token.count(']')
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
@@ -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
- blk.call(node) if pos == (@path.size - 1) && eval("node #{@path[pos]}")
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] == '..'
@@ -86,4 +86,9 @@ describe "JsonPath" do
86
86
  JsonPath.new('$..*').on(@object).to_a.size.should == 28
87
87
  end
88
88
 
89
+ it "should deal with a space in the key name" do
90
+ JsonPath.new("$.'c d'").on({"a" => "a","b" => "b", "c d" => "e"}).to_a.should == ['e']
91
+
92
+ end
93
+
89
94
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
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-03-27 00:00:00 -04:00
17
+ date: 2010-04-27 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20