json_data_extractor 0.0.7 → 0.0.9

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
  SHA256:
3
- metadata.gz: dcd400b724a3b0afebdb95df4ce66929b047a2b13d20be1c377caf1f207288a5
4
- data.tar.gz: ef17fc111fcc824c7b8a54a156b65a91982c6e06883823cfc57521221d541498
3
+ metadata.gz: bdd75c436a18caa753cb6c35536852852b8d876b44684de7f45d66678d012c6b
4
+ data.tar.gz: 612d1cb976811a479e6e3f6c377186d90bd7d8fe900def4009dfeb7e2d63c81d
5
5
  SHA512:
6
- metadata.gz: d2a2c513cc9c18b6500bb3b04b48b67d7559966eab4b63d0254bdeb3c8a732ac667b490df4dcc764277417fb242f8c61fa8cf9b8285c22bf2dd556c995eb0d8f
7
- data.tar.gz: ebb5c2011ef2a188a393aa452250b8034a6c9fc2c7223cbdc2cba32d722fa1504871cd2fd8a75abb5767a4c4832a6e246579578c1a3e12216f501f641dde860b
6
+ metadata.gz: 3137a8b5ecbf8850bbc8f96b46cb9c24688760e1d9c634a0735611a4beadafdf24fb6f1baa66de4f486157a31fbde3b36d1c489e887c1f27c1281225b944748e
7
+ data.tar.gz: 1bdf6749d6c7ba7a86f7c076f0f22a113731938456b801084cbfbd9cb6bd8e15f12a3748a521d4c267a6ad59cacbf40e22ad86d78cb62cc9c09fc0f534ef3076
data/README.md CHANGED
@@ -125,18 +125,18 @@ JDE supports nested schemas. Just provide your element with a type of `array` an
125
125
 
126
126
  E.g. this is a valid real-life schema with nested data:
127
127
 
128
- ```ruby
128
+ ```json
129
129
  {
130
- name: '$.Name',
131
- code: '$.Code',
132
- services: '$.Services[*].Code',
133
- locations: {
134
- path: '$.Locations[*]',
135
- type: 'array',
136
- schema: {
137
- name: '$.Name',
138
- type: '$.Type',
139
- code: '$.Code'
130
+ "name": "$.Name",
131
+ "code": "$.Code",
132
+ "services": "$.Services[*].Code",
133
+ "locations": {
134
+ "path": "$.Locations[*]",
135
+ "type": "array",
136
+ "schema": {
137
+ "name": "$.Name",
138
+ "type": "$.Type",
139
+ "code": "$.Code"
140
140
  }
141
141
  }
142
142
  }
@@ -26,7 +26,7 @@ transformations. The schema is defined as a simple Ruby hash that maps keys to p
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ['lib']
28
28
 
29
- spec.add_development_dependency 'bundler', '~> 1.17'
29
+ spec.add_development_dependency 'bundler'
30
30
  spec.add_development_dependency 'rake', '~> 10.0'
31
31
  spec.add_development_dependency 'rspec', '~> 3.0'
32
32
  spec.add_development_dependency 'pry'
@@ -37,14 +37,17 @@ class JsonDataExtractor
37
37
  else
38
38
  results[key] = apply_modifiers(extracted_data, modifiers)
39
39
 
40
- # TODO yeah, this looks ugly. Address it later.
41
- if !array_type
42
- results[key] = results[key].first unless 1 < results[key].size
43
- elsif nested
44
- results[key] = []
45
- Array(extracted_data).each do |item|
46
- results[key] << self.class.new(item, @modifiers).extract(nested)
47
- end
40
+ if array_type && nested
41
+ results[key] = extract_nested_data(results[key], nested)
42
+ elsif !array_type && nested
43
+ results[key] = extract_nested_data(results[key], nested).first
44
+ elsif !array_type && 1 < results[key].size
45
+ # TODO: handle case where results[key] has more than one item
46
+ # do nothing for now
47
+ elsif array_type && !nested
48
+ # do nothing, it is already an array
49
+ else
50
+ results[key] = results[key].first
48
51
  end
49
52
  end
50
53
  end
@@ -53,6 +56,12 @@ class JsonDataExtractor
53
56
 
54
57
  private
55
58
 
59
+ def extract_nested_data(data, schema)
60
+ Array(data).map do |item|
61
+ self.class.new(item, modifiers).extract(schema)
62
+ end
63
+ end
64
+
56
65
  def apply_modifiers(data, modifiers)
57
66
  data.map do |value|
58
67
  modified_value = value
data/lib/src/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class JsonDataExtractor
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.9'
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_data_extractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Buslaev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-10 00:00:00.000000000 Z
11
+ date: 2023-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.17'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.17'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  - !ruby/object:Gem::Version
137
137
  version: '0'
138
138
  requirements: []
139
- rubygems_version: 3.0.3
139
+ rubygems_version: 3.2.3
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Transform JSON data structures with the help of a simple schema and JsonPath