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 +4 -4
- data/README.md +11 -11
- data/json_data_extractor.gemspec +1 -1
- data/lib/json_data_extractor.rb +17 -8
- data/lib/src/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdd75c436a18caa753cb6c35536852852b8d876b44684de7f45d66678d012c6b
|
4
|
+
data.tar.gz: 612d1cb976811a479e6e3f6c377186d90bd7d8fe900def4009dfeb7e2d63c81d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
```
|
128
|
+
```json
|
129
129
|
{
|
130
|
-
name:
|
131
|
-
code:
|
132
|
-
services:
|
133
|
-
locations: {
|
134
|
-
path:
|
135
|
-
type:
|
136
|
-
schema: {
|
137
|
-
name:
|
138
|
-
type:
|
139
|
-
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
|
}
|
data/json_data_extractor.gemspec
CHANGED
@@ -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'
|
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'
|
data/lib/json_data_extractor.rb
CHANGED
@@ -37,14 +37,17 @@ class JsonDataExtractor
|
|
37
37
|
else
|
38
38
|
results[key] = apply_modifiers(extracted_data, modifiers)
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
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.
|
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-
|
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: '
|
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: '
|
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.
|
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
|