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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac39771f7b1358e30e26bfdc81b5b4ad5ac493238e84142e31331648f96fa37e
4
- data.tar.gz: 69a0d03f65e05dfb292ae01f950986822ec04991771968ede64c63c6f202d99f
3
+ metadata.gz: bdd75c436a18caa753cb6c35536852852b8d876b44684de7f45d66678d012c6b
4
+ data.tar.gz: 612d1cb976811a479e6e3f6c377186d90bd7d8fe900def4009dfeb7e2d63c81d
5
5
  SHA512:
6
- metadata.gz: 403b5b95e7bfc0b7f530021980a10407f08be499092a80550a2dc55df7aeabc64197f68e6bf44f98c19be4ea8d57884db1205490970a57552ea924cf673c0f8a
7
- data.tar.gz: 58260729ea70e88fdd1937cbbac0cffac998ce9dab686dedbbcb110e7618edd72a9bd71e494bfdc7441665a306e3ead800d9558b4c80b2fce525de3c70f90eee
6
+ metadata.gz: 3137a8b5ecbf8850bbc8f96b46cb9c24688760e1d9c634a0735611a4beadafdf24fb6f1baa66de4f486157a31fbde3b36d1c489e887c1f27c1281225b944748e
7
+ data.tar.gz: 1bdf6749d6c7ba7a86f7c076f0f22a113731938456b801084cbfbd9cb6bd8e15f12a3748a521d4c267a6ad59cacbf40e22ad86d78cb62cc9c09fc0f534ef3076
@@ -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,20 +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
- if nested
43
- results[key] = self.class.new(results[key].first, @modifiers).extract(nested)
44
- # todo there might be a problem if results[key] yields more than 1 item
45
- # Yeah, we'll get back to it later. Or send your PRs
46
- else
47
- results[key] = results[key].first unless 1 < results[key].size
48
- end
49
- elsif nested
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
@@ -1,3 +1,3 @@
1
1
  class JsonDataExtractor
2
- VERSION = '0.0.8'
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.8
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-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