world_bank_fetcher 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/world_bank_fetcher.rb
CHANGED
@@ -14,15 +14,20 @@ module WorldBankFetcher
|
|
14
14
|
def fetch
|
15
15
|
all_data = fetch_everything query
|
16
16
|
if all_data
|
17
|
-
data = CountryParser.filter(all_data)
|
18
|
-
data
|
17
|
+
data = @job_type == :country ? CountryParser.filter(all_data) : IndicatorDataParser.filter(all_data)
|
18
|
+
@checksum = checksum data
|
19
|
+
{:results => data, :checksum => @checksum}
|
19
20
|
else
|
20
21
|
nil
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
private
|
25
|
-
|
26
|
+
|
27
|
+
def checksum(data)
|
28
|
+
Digest::MD5.hexdigest Marshal.dump(data)
|
29
|
+
end
|
30
|
+
|
26
31
|
def build_query(options)
|
27
32
|
options[:indicator] ? indicator_query(options[:indicator]) : countries_query
|
28
33
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module WorldBankFetcher
|
4
|
+
describe IndicatorDataParser do
|
5
|
+
let(:other_attributes) { { }}
|
6
|
+
let(:good_data_1) { WorldBank::Data.new(attrs_with 'value' => 534) }
|
7
|
+
let(:good_data_2) { WorldBank::Data.new(attrs_with 'value' => 32) }
|
8
|
+
let(:bad_data_1) { WorldBank::Data.new(attrs_with 'value' => nil) }
|
9
|
+
let(:bad_data_2) { WorldBank::Data.new(attrs_with 'value' => nil) }
|
10
|
+
|
11
|
+
|
12
|
+
it "should filter data with nil values" do
|
13
|
+
# CountryParser.filter([france, arab_world, canada]).should eq([france, canada])
|
14
|
+
good_data = [good_data_1, good_data_2]
|
15
|
+
IndicatorDataParser.filter([good_data_1, bad_data_2, bad_data_1, good_data_2]).should eq(good_data)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def attrs_with(attr)
|
21
|
+
{'indicator' => {'value' => '2', 'id' => 23}, 'date' => '1999'}.merge attr
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/spec/job_spec.rb
CHANGED
@@ -1,45 +1,98 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
module WorldBankFetcher
|
4
|
-
describe Job do
|
4
|
+
describe Job do
|
5
|
+
before do
|
6
|
+
CountryParser.stub!(:filter) do |arg|
|
7
|
+
arg
|
8
|
+
end
|
9
|
+
|
10
|
+
IndicatorDataParser.stub!(:filter) do |arg|
|
11
|
+
arg
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
let(:indicator_string) { 'SP.POP.TOTL' }
|
6
16
|
|
7
|
-
|
17
|
+
context 'initialize' do
|
8
18
|
it "should accept hash w/ indicator to specify job type in intializer" do
|
9
|
-
country_parser_filters_nothing!
|
10
19
|
WorldBank::Data.should_receive(:country).with('all').and_return(stubbed_query)
|
11
20
|
Job.new(:indicator => indicator_string)
|
12
21
|
end
|
13
22
|
|
14
23
|
it "should accept countries to indicate all countries in initializer hash" do
|
15
|
-
country_parser_filters_nothing!
|
16
24
|
WorldBank::Country.should_receive(:all).and_return(stubbed_query)
|
17
25
|
Job.new(:countries => true)
|
18
26
|
end
|
19
27
|
end
|
20
28
|
|
21
|
-
|
29
|
+
context 'fetch' do
|
30
|
+
context 'filtering' do
|
31
|
+
it "should not use IndicatorDataParser to filter for country jobs" do
|
32
|
+
IndicatorDataParser.should_not_receive(:filter)
|
33
|
+
Job.new(:countries => true).fetch
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should use IndicatorDataParser to filter for indicator jobs" do
|
37
|
+
WorldBank::DataQuery.any_instance.stub(:total).and_return(39)
|
38
|
+
QueryScheduler.any_instance.should_receive(:execute!).and_return(:something)
|
39
|
+
|
40
|
+
IndicatorDataParser.should_receive(:filter)
|
41
|
+
Job.new(:indicator => indicator_string).fetch
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should not use CountryParser to filter for indicator jobs" do
|
45
|
+
WorldBank::DataQuery.any_instance.stub(:total).and_return(39)
|
46
|
+
QueryScheduler.any_instance.should_receive(:execute!).and_return(:something)
|
47
|
+
|
48
|
+
CountryParser.should_not_receive(:filter)
|
49
|
+
Job.new(:indicator => indicator_string).fetch
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should use CountryParser to filter for country jobs" do
|
53
|
+
CountryParser.should_receive(:filter)
|
54
|
+
Job.new(:countries => true).fetch
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
22
58
|
it "should return nil if query shceduler returns nil" do
|
23
|
-
|
59
|
+
WorldBank::DataQuery.any_instance.stub(:total).and_return(39)
|
24
60
|
QueryScheduler.any_instance.should_receive(:execute!).and_return(nil)
|
25
61
|
job = Job.new(:indicator => indicator_string)
|
26
62
|
job.fetch.should be_nil
|
27
63
|
end
|
28
64
|
|
29
65
|
it "should not return nil if query shceduler returns non nil value" do
|
30
|
-
|
66
|
+
WorldBank::DataQuery.any_instance.stub(:total).and_return(39)
|
31
67
|
QueryScheduler.any_instance.should_receive(:execute!).and_return(:something)
|
32
68
|
job = Job.new(:indicator => indicator_string)
|
33
69
|
job.fetch.should_not be_nil
|
34
70
|
end
|
35
71
|
|
36
|
-
it "
|
72
|
+
it "returns a hash if there are no errors" do
|
73
|
+
WorldBank::DataQuery.any_instance.stub(:total).and_return(39)
|
37
74
|
QueryScheduler.any_instance.should_receive(:execute!).and_return(:something)
|
38
|
-
|
75
|
+
|
39
76
|
job = Job.new(:indicator => indicator_string)
|
40
|
-
job.fetch.should
|
77
|
+
job.fetch.should be_an_instance_of(Hash)
|
41
78
|
end
|
42
|
-
|
79
|
+
|
80
|
+
context 'checksum' do
|
81
|
+
it "should return unique checksums given unique results" do
|
82
|
+
job = Job.new(:indicator => indicator_string)
|
83
|
+
d1 = [:blah, :blog, :dj]
|
84
|
+
d2 = [:bjad, :awe, :asdf]
|
85
|
+
job.send(:checksum, d1).should_not eq(job.send(:checksum, d2))
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should receive same checksum if scheduler returns identical results" do
|
89
|
+
job = Job.new(:indicator => indicator_string)
|
90
|
+
d1 = [:blah, :blog, :dj]
|
91
|
+
job.send(:checksum, d1).should eq(job.send(:checksum, d1))
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
43
96
|
|
44
97
|
private
|
45
98
|
def stubbed_query
|
@@ -47,11 +100,5 @@ module WorldBankFetcher
|
|
47
100
|
dummy_query.stub(:indicator)
|
48
101
|
dummy_query
|
49
102
|
end
|
50
|
-
|
51
|
-
def country_parser_filters_nothing!
|
52
|
-
CountryParser.stub!(:filter) do |arg|
|
53
|
-
arg
|
54
|
-
end
|
55
|
-
end
|
56
103
|
end
|
57
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: world_bank_fetcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -61,11 +61,13 @@ files:
|
|
61
61
|
- country_lists/sorted_countries.txt
|
62
62
|
- lib/world_bank_fetcher.rb
|
63
63
|
- lib/world_bank_fetcher/country_parser.rb
|
64
|
+
- lib/world_bank_fetcher/indicator_data_parser.rb
|
64
65
|
- lib/world_bank_fetcher/job.rb
|
65
66
|
- lib/world_bank_fetcher/query_scheduler.rb
|
66
67
|
- lib/world_bank_fetcher/version.rb
|
67
68
|
- spec/country_parser_spec.rb
|
68
69
|
- spec/helper.rb
|
70
|
+
- spec/indicator_data_parser_spec.rb
|
69
71
|
- spec/job_spec.rb
|
70
72
|
- spec/query_scheduler_spec.rb
|
71
73
|
- world_bank_fetcher.gemspec
|
@@ -83,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
85
|
version: '0'
|
84
86
|
segments:
|
85
87
|
- 0
|
86
|
-
hash: -
|
88
|
+
hash: -4294314482202653082
|
87
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
90
|
none: false
|
89
91
|
requirements:
|
@@ -92,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
94
|
version: '0'
|
93
95
|
segments:
|
94
96
|
- 0
|
95
|
-
hash: -
|
97
|
+
hash: -4294314482202653082
|
96
98
|
requirements: []
|
97
99
|
rubyforge_project:
|
98
100
|
rubygems_version: 1.8.24
|
@@ -102,5 +104,6 @@ summary: Fetches local WorldBank country and indicator data.
|
|
102
104
|
test_files:
|
103
105
|
- spec/country_parser_spec.rb
|
104
106
|
- spec/helper.rb
|
107
|
+
- spec/indicator_data_parser_spec.rb
|
105
108
|
- spec/job_spec.rb
|
106
109
|
- spec/query_scheduler_spec.rb
|