world_bank_fetcher 0.0.8 → 0.0.9
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/{country_list.txt → country_lists/country_list.txt} +0 -0
- data/{non_country_list.txt → country_lists/non_country_list.txt} +0 -0
- data/{sorted_countries.txt → country_lists/sorted_countries.txt} +0 -0
- data/lib/world_bank_fetcher/country_parser.rb +49 -10
- data/lib/world_bank_fetcher/job.rb +3 -2
- data/lib/world_bank_fetcher/version.rb +1 -1
- data/lib/world_bank_fetcher.rb +0 -1
- data/spec/country_parser_spec.rb +9 -27
- data/spec/job_spec.rb +0 -4
- metadata +6 -9
- data/lib/world_bank_fetcher/data_parser.rb +0 -16
- data/spec/data_parser_spec.rb +0 -47
File without changes
|
File without changes
|
File without changes
|
@@ -2,16 +2,55 @@ require 'world_bank'
|
|
2
2
|
|
3
3
|
module WorldBankFetcher
|
4
4
|
class CountryParser
|
5
|
-
|
6
|
-
|
7
|
-
data_collection.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
results << current_country
|
13
|
-
end
|
14
|
-
results
|
5
|
+
|
6
|
+
def self.filter(data_collection)
|
7
|
+
data_collection.reject {|country| non_country_codes.include? country.iso2_code }
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.non_country_codes
|
11
|
+
NON_COUNTRIES.map {|country_info| country_info[:iso2_code] }
|
15
12
|
end
|
13
|
+
|
14
|
+
NON_COUNTRIES = [
|
15
|
+
{:name => "Arab World", :iso2_code => "1A"},
|
16
|
+
{:name => "Caribbean small states", :iso2_code => "S3"},
|
17
|
+
{:name => "East Asia & Pacific (developing only)", :iso2_code => "4E"},
|
18
|
+
{:name => "East Asia & Pacific (all income levels)", :iso2_code => "Z4"},
|
19
|
+
{:name => "Europe & Central Asia (developing only)", :iso2_code => "7E"},
|
20
|
+
{:name => "Europe & Central Asia (all income levels)", :iso2_code => "Z7"},
|
21
|
+
{:name => "Euro area", :iso2_code => "XC"},
|
22
|
+
{:name => "European Union", :iso2_code => "EU"},
|
23
|
+
{:name => "High income", :iso2_code => "XD"},
|
24
|
+
{:name => "Heavily indebted poor countries (HIPC)", :iso2_code => "XE"},
|
25
|
+
{:name => "Not classified", :iso2_code => "XY"},
|
26
|
+
{:name => "Latin America & Caribbean (developing only)", :iso2_code => "XJ"},
|
27
|
+
{:name => "Latin America & Caribbean (all income levels)", :iso2_code => "ZJ"},
|
28
|
+
{:name => "Least developed countries: UN classification", :iso2_code => "XL"},
|
29
|
+
{:name => "Low income", :iso2_code => "XM"},
|
30
|
+
{:name => "Lower middle income", :iso2_code => "XN"},
|
31
|
+
{:name => "Low & middle income", :iso2_code => "XO"},
|
32
|
+
{:name => "Middle East & North Africa (all income levels)", :iso2_code => "ZQ"},
|
33
|
+
{:name => "Middle income", :iso2_code => "XP"},
|
34
|
+
{:name => "Middle East & North Africa (developing only)", :iso2_code => "XQ"},
|
35
|
+
{:name => "North America", :iso2_code => "XU"},
|
36
|
+
{:name => "High income: nonOECD", :iso2_code => "XR"},
|
37
|
+
{:name => "High income: OECD", :iso2_code => "XS"},
|
38
|
+
{:name => "OECD members", :iso2_code => "OE"},
|
39
|
+
{:name => "Other small states", :iso2_code => "S4"},
|
40
|
+
{:name => "Pacific island small states", :iso2_code => "S2"},
|
41
|
+
{:name => "South Asia", :iso2_code => "8S"},
|
42
|
+
{:name => "Sub-Saharan Africa (developing only)", :iso2_code => "ZF"},
|
43
|
+
{:name => "Sub-Saharan Africa (all income levels)", :iso2_code => "ZG"},
|
44
|
+
{:name => "Small states", :iso2_code => "S1"},
|
45
|
+
{:name => "Upper middle income", :iso2_code => "XT"},
|
46
|
+
{:name => "World", :iso2_code => "1W"}
|
47
|
+
]
|
16
48
|
end
|
17
49
|
end
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
@@ -12,8 +12,9 @@ module WorldBankFetcher
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def fetch
|
15
|
-
|
16
|
-
if
|
15
|
+
all_data = fetch_all_data query
|
16
|
+
if all_data
|
17
|
+
data = @job_type == :indicator ? all_data : CountryParser.filter(all_data)
|
17
18
|
@checksum = checksum data
|
18
19
|
{:results => data, :checksum => @checksum}
|
19
20
|
else
|
data/lib/world_bank_fetcher.rb
CHANGED
data/spec/country_parser_spec.rb
CHANGED
@@ -2,32 +2,14 @@ require 'helper'
|
|
2
2
|
|
3
3
|
module WorldBankFetcher
|
4
4
|
describe CountryParser do
|
5
|
-
let(:france) {
|
6
|
-
let(:canada) {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
expected = [{:name => "France", :capital => "Paris", :region => "Europe"},
|
15
|
-
{:name => "Canada", :capital => "Ottawa", :region => "North America"} ]
|
16
|
-
CountryParser.parse([france, canada]).should eq(expected)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
def mock_country(name, capital, region_name)
|
21
|
-
region_hash = Object.new
|
22
|
-
raw_object = Object.new
|
23
|
-
raw_object.stub(:value).and_return(region_name)
|
24
|
-
region_hash.stub(:raw).and_return(raw_object)
|
25
|
-
country = double('country')
|
26
|
-
country.stub(:name).and_return(name)
|
27
|
-
country.stub(:capital).and_return(capital)
|
28
|
-
country.stub(:region).and_return(region_hash)
|
29
|
-
country
|
30
|
-
end
|
31
|
-
|
5
|
+
let(:france) { WorldBank::Country.new('name' => 'France', 'iso2Code' => 'FR')}
|
6
|
+
let(:canada) { WorldBank::Country.new('name' => 'Canada', 'iso2Code' => 'CA')}
|
7
|
+
let(:arab_world) { WorldBank::Country.new('name' => 'Arab World', 'iso2Code' => '1A')}
|
8
|
+
let(:euro_area) {WorldBank::Country.new('name' => "Euro area", 'iso2Code' => "XC")}
|
9
|
+
|
10
|
+
it "should filter expected countries" do
|
11
|
+
CountryParser.filter([france, arab_world, canada]).should eq([france, canada])
|
12
|
+
CountryParser.filter([canada, euro_area, france, arab_world]).should eq([canada, france])
|
13
|
+
end
|
32
14
|
end
|
33
15
|
end
|
data/spec/job_spec.rb
CHANGED
@@ -3,10 +3,6 @@ require 'helper'
|
|
3
3
|
module WorldBankFetcher
|
4
4
|
describe Job do
|
5
5
|
let(:indicator_string) { 'SP.POP.TOTL' }
|
6
|
-
|
7
|
-
before do
|
8
|
-
DataParser.stub(:parse).and_return(:something)
|
9
|
-
end
|
10
6
|
|
11
7
|
context 'initialize' do
|
12
8
|
it "should accept hash w/ indicator to specify job type in intializer" do
|
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.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -56,17 +56,15 @@ files:
|
|
56
56
|
- LICENSE
|
57
57
|
- README.md
|
58
58
|
- Rakefile
|
59
|
-
- country_list.txt
|
59
|
+
- country_lists/country_list.txt
|
60
|
+
- country_lists/non_country_list.txt
|
61
|
+
- country_lists/sorted_countries.txt
|
60
62
|
- lib/world_bank_fetcher.rb
|
61
63
|
- lib/world_bank_fetcher/country_parser.rb
|
62
|
-
- lib/world_bank_fetcher/data_parser.rb
|
63
64
|
- lib/world_bank_fetcher/job.rb
|
64
65
|
- lib/world_bank_fetcher/query_scheduler.rb
|
65
66
|
- lib/world_bank_fetcher/version.rb
|
66
|
-
- non_country_list.txt
|
67
|
-
- sorted_countries.txt
|
68
67
|
- spec/country_parser_spec.rb
|
69
|
-
- spec/data_parser_spec.rb
|
70
68
|
- spec/helper.rb
|
71
69
|
- spec/job_spec.rb
|
72
70
|
- spec/query_scheduler_spec.rb
|
@@ -85,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
83
|
version: '0'
|
86
84
|
segments:
|
87
85
|
- 0
|
88
|
-
hash:
|
86
|
+
hash: 780221342756096436
|
89
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
88
|
none: false
|
91
89
|
requirements:
|
@@ -94,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
92
|
version: '0'
|
95
93
|
segments:
|
96
94
|
- 0
|
97
|
-
hash:
|
95
|
+
hash: 780221342756096436
|
98
96
|
requirements: []
|
99
97
|
rubyforge_project:
|
100
98
|
rubygems_version: 1.8.24
|
@@ -103,7 +101,6 @@ specification_version: 3
|
|
103
101
|
summary: Fetches local WorldBank country and indicator data.
|
104
102
|
test_files:
|
105
103
|
- spec/country_parser_spec.rb
|
106
|
-
- spec/data_parser_spec.rb
|
107
104
|
- spec/helper.rb
|
108
105
|
- spec/job_spec.rb
|
109
106
|
- spec/query_scheduler_spec.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'world_bank'
|
2
|
-
|
3
|
-
module WorldBankFetcher
|
4
|
-
class DataParser
|
5
|
-
def self.parse(data_collection)
|
6
|
-
indicator_id = data_collection.first.id
|
7
|
-
results = {:id => indicator_id }
|
8
|
-
data_collection.each do |datum|
|
9
|
-
return nil unless datum.id === indicator_id
|
10
|
-
results[datum.others['country']['value']] ||= []
|
11
|
-
results[datum.others['country']['value']] << { :year => datum.date, :value => datum.value }
|
12
|
-
end
|
13
|
-
results
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/spec/data_parser_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module WorldBankFetcher
|
4
|
-
describe DataParser do
|
5
|
-
let(:indicator_id) { 'DJ.JIE.JIDL' }
|
6
|
-
let(:datum1) { mock_data(:country => 'Mexico', :year => 1990, :id => indicator_id, :value => 234) }
|
7
|
-
let(:data) { [datum1] }
|
8
|
-
|
9
|
-
it "should parse data and return expected hash structure" do
|
10
|
-
actual = DataParser.parse data
|
11
|
-
actual.should eq({:id => indicator_id, 'Mexico' => [{:year => 1990, :value => 234}]})
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should return nil when provided data for multiple indicators" do
|
15
|
-
datum2 = mock_data(:country => 'Mexico', :year => 1990, :id => 'NJ.EKD.DKEL', :value => 234)
|
16
|
-
DataParser.parse([datum1, datum2]).should be_nil
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should handle more complext data" do
|
20
|
-
d1 = mock_data(:country => 'Mexico', :year => 1990, :id => indicator_id, :value => 234)
|
21
|
-
d2 = mock_data(:country => 'Mexico', :year => 1992, :id => indicator_id, :value => 456)
|
22
|
-
d3 = mock_data(:country => 'France', :year => 1990, :id => indicator_id, :value => 789)
|
23
|
-
expected = {:id => indicator_id, 'Mexico' => [{:year => 1990, :value => 234}, {:year => 1992, :value => 456}], 'France' => [{:year => 1990, :value => 789}]}
|
24
|
-
|
25
|
-
DataParser.parse([d1,d2,d3]).should eq(expected)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should mock data properly" do
|
29
|
-
f = data.first
|
30
|
-
f.value.should eq(234)
|
31
|
-
f.id.should eq('DJ.JIE.JIDL')
|
32
|
-
f.date.should eq(1990)
|
33
|
-
f.others['country']['value'].should eq('Mexico')
|
34
|
-
end
|
35
|
-
|
36
|
-
def mock_data(attr)
|
37
|
-
mockal = Object.new
|
38
|
-
mockal.stub(:value).and_return(attr[:value])
|
39
|
-
mockal.stub(:id).and_return(attr[:id])
|
40
|
-
mockal.stub(:date).and_return(attr[:year])
|
41
|
-
|
42
|
-
country_data = {'country' => {'value' => attr[:country]}}
|
43
|
-
mockal.stub(:others).and_return(country_data)
|
44
|
-
mockal
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|