turbot-runner 0.1.26 → 0.1.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmZhZTI1N2ZkMWFlODhiOGEwNjlhMGE4MzkwMjk1MmQ5OTc2YjcyNg==
4
+ ZWIwOWIxZjA3YTkxYWE4MjY2N2VhYzI2MzAxNGJkMGI2N2Y5NGM5Zg==
5
5
  data.tar.gz: !binary |-
6
- NDU1MTY4Yzk1ZDJkMmEwYjM0N2YxMDI3N2IxYjVlYTg0MDE0MTU1Mw==
6
+ NGZjZmUxMzk1ZWJlN2MxZGY5MGUxM2M4NzkyMjE1YTA0ZTFkY2M3Zg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OGI4ZjgyOTJjZGI3ZTVhZWY4YWQ3YzE4Y2I0MjIwZjU3ZDZjZWZjYjk4OTYy
10
- N2ViZWM2ZTlkMTcxYWUxZjQ1ZTBkNjBjMjc3MWRhYjhiZThkZWZkYTljMjlh
11
- YTkwZjY1OTNiYzBjNWE3N2NlODcyNjFkMjkzNWM3NzI1YjFjYTQ=
9
+ MDE3NmM3MjY2ODhlMzM4NmU1ZDdkM2RkOGFhNmU5MzNhZjc3MTY3MDQyZjA4
10
+ ZTBlNDFmZTRkMDBhYWY3OWY3Mjg1Mjk0NjZlZjk4ODVjNGQzNWVlMDVmMGU3
11
+ MmUxZWZmZDBkNDdjYWZkY2U1Y2Q2ZmMyOWYxNGYyZWI0ZDU2MTE=
12
12
  data.tar.gz: !binary |-
13
- ODdjNTI1YWNjOWUyOGEzY2ZlYWZhOWFmM2Y5MDNiMWE1Mzc4MDE3YmE2ZTU3
14
- YTg1NDFiZGNmOWZkNDY3N2IyOWY5YTAwNzc5NDFjYWQ1Y2U4YWUyMDFmZWJm
15
- ZmU5NWJmMjU0MzJlN2Q0MzQ0NGFkMzhiNDZkYWRlMTNlZjY4OTk=
13
+ MDlhNTM3ZWM2NjQ5OTk1MWY2Y2JjZTkyYTMwZTBlMGQ4ZDIxNDczNzZkM2Ex
14
+ YmZlZTcwMDgwM2ZlOTM1MzMwZTQ0ZWRhMmE3OTIxNjMxYjY1YzQ5MTRiZTk4
15
+ ODIzYjY4ZWUyNjQzMjQwYzJmN2MwN2Q2NmM2NzAxNjM4Mjg1Y2U=
@@ -5,5 +5,43 @@ module TurbotRunner
5
5
  def deep_copy(thing)
6
6
  Marshal.load(Marshal.dump(thing))
7
7
  end
8
+
9
+ # This turns a hash of the form:
10
+ #
11
+ # {
12
+ # 'a' => {
13
+ # 'b' => {
14
+ # 'c' => '123',
15
+ # 'd' => '124',
16
+ # },
17
+ # 'e' => {
18
+ # 'f' => '156',
19
+ # }
20
+ # }
21
+ # }
22
+ #
23
+ # into a hash of the form:
24
+ #
25
+ # {
26
+ # 'a.b.c' => '123',
27
+ # 'a.b.d' => '124',
28
+ # 'a.e.f' => '156',
29
+ # }
30
+ def flatten(hash)
31
+ pairs = []
32
+
33
+ hash.each do |k, v|
34
+ case v
35
+ when Hash
36
+ flatten(v).each do |k1, v1|
37
+ pairs << ["#{k}.#{k1}", v1]
38
+ end
39
+ else
40
+ pairs << [k, v]
41
+ end
42
+ end
43
+
44
+ Hash[pairs]
45
+ end
8
46
  end
9
47
  end
@@ -9,7 +9,9 @@ module TurbotRunner
9
9
  message = nil
10
10
 
11
11
  if error.nil?
12
- identifying_attributes = record.reject do |k, v|
12
+ flattened_record = TurbotRunner::Utils.flatten(record)
13
+
14
+ identifying_attributes = flattened_record.reject do |k, v|
13
15
  !identifying_fields.include?(k) || v.nil? || v == ''
14
16
  end
15
17
 
@@ -1,3 +1,3 @@
1
1
  module TurbotRunner
2
- VERSION = '0.1.26'
2
+ VERSION = '0.1.27'
3
3
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe TurbotRunner::Utils do
4
+ specify '.flatten' do
5
+ hash = {
6
+ 'a' => {
7
+ 'b' => {
8
+ 'c' => '123',
9
+ 'd' => '124',
10
+ },
11
+ 'e' => {
12
+ 'f' => '156',
13
+ }
14
+ }
15
+ }
16
+
17
+ expect(TurbotRunner::Utils.flatten(hash)).to eq({
18
+ 'a.b.c' => '123',
19
+ 'a.b.d' => '124',
20
+ 'a.e.f' => '156',
21
+ })
22
+ end
23
+ end
@@ -48,5 +48,42 @@ describe TurbotRunner::Validator do
48
48
  expected_error = 'Property not of expected format: sample_date (must be of format yyyy-mm-dd)'
49
49
  expect(record).to fail_validation_with(expected_error)
50
50
  end
51
+
52
+ context 'with nested identifying fields' do
53
+ specify 'with record missing all identifying fields' do
54
+ record = {
55
+ 'sample_date' => '2014-06-01',
56
+ 'source_url' => 'http://example.com/123',
57
+ 'one' => {'two' => {}},
58
+ 'four' => {}
59
+ }
60
+ identifying_fields = ['one.two.three', 'four.five.six']
61
+ error = TurbotRunner::Validator.validate('primary-data', record, identifying_fields)
62
+ expect(error).to eq('There were no values provided for any of the identifying fields: one.two.three, four.five.six')
63
+ end
64
+
65
+ specify 'with record missing some identifying fields' do
66
+ record = {
67
+ 'sample_date' => '2014-06-01',
68
+ 'source_url' => 'http://example.com/123',
69
+ 'one' => {'two' => {'three' => 123}}
70
+ }
71
+ identifying_fields = ['one.two.three', 'four.five.six']
72
+ error = TurbotRunner::Validator.validate('primary-data', record, identifying_fields)
73
+ expect(error).to eq(nil)
74
+ end
75
+
76
+ specify 'with record missing no identifying fields' do
77
+ record = {
78
+ 'sample_date' => '2014-06-01',
79
+ 'source_url' => 'http://example.com/123',
80
+ 'one' => {'two' => {'three' => 123}},
81
+ 'four' => {'five' => {'six' => 456}}
82
+ }
83
+ identifying_fields = ['one.two.three', 'four.five.six']
84
+ error = TurbotRunner::Validator.validate('primary-data', record, identifying_fields)
85
+ expect(error).to eq(nil)
86
+ end
87
+ end
51
88
  end
52
89
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbot-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.26
4
+ version: 0.1.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenCorporates
@@ -110,6 +110,7 @@ files:
110
110
  - spec/bots/slow-bot/scraper.rb
111
111
  - spec/lib/processor_spec.rb
112
112
  - spec/lib/runner_spec.rb
113
+ - spec/lib/utils_spec.rb
113
114
  - spec/lib/validator_spec.rb
114
115
  - spec/manual_spec.rb
115
116
  - spec/outputs/full-scraper.out