jsonpath 0.9.6 → 0.9.7

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: 966e3b0fe3897b291f4986554eab5505834ae395
4
- data.tar.gz: c5765190e2274b20387c0cdd477c76091a3b7af3
3
+ metadata.gz: 78e6fd3aa1c1d43001e53b13939d06e137441a52
4
+ data.tar.gz: 8d92b85875c0eddbb9f7c2997b21adcee58bcded
5
5
  SHA512:
6
- metadata.gz: ec8346c801fece96fa75b56dce3611fab9fd6b2b3eec9bf05264ed0c27a21b34460412e1232502f868cd8677e16353c5676dfb9bcfeae963d78fac6a95eb46b6
7
- data.tar.gz: 7a5eb3b65176488311eb1467fbbecad8a1df4a7adc57a3f76546e67cda6733331fabc612b3afc127f06a61b236dee125e738bae1b543f601b1844a7feb609870
6
+ metadata.gz: 488e03a62223442af4449f9c237767e31a7f0044f228049884916bd92e283a4c5efb22c8f7e1800726dc16cf60f5c7801a5788a4b847150b7dc0794244cc41a1
7
+ data.tar.gz: 4a5ab8b934507c86bb7591bf2e894eb8084818d9216bae696b094452be1b8e92f270b3b903b711f6b5a82f6903dd1a267ea868398ad21ca4d1c28a21e71ba0c4
@@ -65,8 +65,14 @@ class JsonPath
65
65
  res
66
66
  end
67
67
 
68
- def on(obj_or_str)
69
- enum_on(obj_or_str).to_a
68
+ def on(obj_or_str, opts = {})
69
+ a = enum_on(obj_or_str).to_a
70
+ if opts[:symbolize_keys]
71
+ a.map! do |e|
72
+ e.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo }
73
+ end
74
+ end
75
+ a
70
76
  end
71
77
 
72
78
  def first(obj_or_str, *args)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class JsonPath
4
- VERSION = '0.9.6'.freeze
4
+ VERSION = '0.9.7'.freeze
5
5
  end
@@ -610,6 +610,49 @@ class TestJsonpath < MiniTest::Unit::TestCase
610
610
  assert_equal ['data'], JsonPath.new("$.{data}").on(data)
611
611
  end
612
612
 
613
+ def test_symbolize
614
+ data = '
615
+ {
616
+ "store": {
617
+ "bicycle": {
618
+ "price": 19.95,
619
+ "color": "red"
620
+ },
621
+ "book": [
622
+ {
623
+ "price": 8.95,
624
+ "category": "reference",
625
+ "title": "Sayings of the Century",
626
+ "author": "Nigel Rees"
627
+ },
628
+ {
629
+ "price": 12.99,
630
+ "category": "fiction",
631
+ "title": "Sword of Honour",
632
+ "author": "Evelyn Waugh"
633
+ },
634
+ {
635
+ "price": 8.99,
636
+ "category": "fiction",
637
+ "isbn": "0-553-21311-3",
638
+ "title": "Moby Dick",
639
+ "author": "Herman Melville",
640
+ "color": "blue"
641
+ },
642
+ {
643
+ "price": 22.99,
644
+ "category": "fiction",
645
+ "isbn": "0-395-19395-8",
646
+ "title": "The Lord of the Rings",
647
+ "author": "Tolkien"
648
+ }
649
+ ]
650
+ }
651
+ }
652
+ '
653
+ assert_equal [{:price=>8.95, :category=>"reference", :title=>"Sayings of the Century", :author=>"Nigel Rees"}, {:price=>8.99, :category=>"fiction", :isbn=>"0-553-21311-3", :title=>"Moby Dick", :author=>"Herman Melville", :color=>"blue"}], JsonPath.new('$..book[::2]').on(data, {symbolize_keys: true})
654
+ end
655
+
613
656
  def test_changed
614
657
  json =
615
658
  {
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.9.6
4
+ version: 0.9.7
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: 2018-10-30 00:00:00.000000000 Z
12
+ date: 2018-12-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json