json_data_extractor 0.0.8 → 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/json_data_extractor.gemspec +1 -1
- data/lib/json_data_extractor.rb +17 -14
- data/lib/src/version.rb +1 -1
- metadata +6 -6
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/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,20 +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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
results[key] = []
|
51
|
-
Array(extracted_data).each do |item|
|
52
|
-
results[key] << self.class.new(item, @modifiers).extract(nested)
|
53
|
-
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
|
54
51
|
end
|
55
52
|
end
|
56
53
|
end
|
@@ -59,6 +56,12 @@ class JsonDataExtractor
|
|
59
56
|
|
60
57
|
private
|
61
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
|
+
|
62
65
|
def apply_modifiers(data, modifiers)
|
63
66
|
data.map do |value|
|
64
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-05-
|
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
|