worldbank_as_dataframe 0.1.0
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.
- checksums.yaml +7 -0
- data/.autotest +1 -0
- data/.gemtest +0 -0
- data/.gitignore +42 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/.yardopts +3 -0
- data/Changelog +6 -0
- data/Gemfile +4 -0
- data/LICENSE.md +10 -0
- data/README.md +164 -0
- data/Rakefile +16 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/worldbank_as_dataframe/client.rb +69 -0
- data/lib/worldbank_as_dataframe/country.rb +326 -0
- data/lib/worldbank_as_dataframe/data.rb +47 -0
- data/lib/worldbank_as_dataframe/data_query.rb +82 -0
- data/lib/worldbank_as_dataframe/income_level.rb +23 -0
- data/lib/worldbank_as_dataframe/indicator.rb +42 -0
- data/lib/worldbank_as_dataframe/lending_type.rb +23 -0
- data/lib/worldbank_as_dataframe/param_query.rb +51 -0
- data/lib/worldbank_as_dataframe/queriable.rb +39 -0
- data/lib/worldbank_as_dataframe/query.rb +213 -0
- data/lib/worldbank_as_dataframe/region.rb +22 -0
- data/lib/worldbank_as_dataframe/source.rb +25 -0
- data/lib/worldbank_as_dataframe/topic.rb +25 -0
- data/lib/worldbank_as_dataframe/version.rb +3 -0
- data/lib/worldbank_as_dataframe.rb +21 -0
- data/spec/fixtures/brazil.json +43 -0
- data/spec/fixtures/countries.json +2 -0
- data/spec/fixtures/countries_india.json +2 -0
- data/spec/fixtures/income_level_lmc.json +1 -0
- data/spec/fixtures/income_levels.json +2 -0
- data/spec/fixtures/indicators.json +2 -0
- data/spec/fixtures/indicators_tractors.json +1 -0
- data/spec/fixtures/lending_type_idb.json +1 -0
- data/spec/fixtures/lending_types.json +1 -0
- data/spec/fixtures/regions.json +2 -0
- data/spec/fixtures/regions_world.json +1 -0
- data/spec/fixtures/source_21.json +2 -0
- data/spec/fixtures/sources.json +1 -0
- data/spec/fixtures/topic_6.json +2 -0
- data/spec/fixtures/topics.json +2 -0
- data/spec/helper.rb +48 -0
- data/spec/worldbank_as_dataframe/client_spec.rb +23 -0
- data/spec/worldbank_as_dataframe/country_spec.rb +35 -0
- data/spec/worldbank_as_dataframe/data_query_spec.rb +38 -0
- data/spec/worldbank_as_dataframe/data_spec.rb +26 -0
- data/spec/worldbank_as_dataframe/income_level_spec.rb +26 -0
- data/spec/worldbank_as_dataframe/indicator_spec.rb +38 -0
- data/spec/worldbank_as_dataframe/lending_type_spec.rb +26 -0
- data/spec/worldbank_as_dataframe/param_query_spec.rb +45 -0
- data/spec/worldbank_as_dataframe/query_spec.rb +83 -0
- data/spec/worldbank_as_dataframe/region_spec.rb +29 -0
- data/spec/worldbank_as_dataframe/source_spec.rb +32 -0
- data/spec/worldbank_as_dataframe/topic_spec.rb +35 -0
- data/spec/worldbank_as_dataframe_spec.rb +9 -0
- data/worldbank_as_dataframe.gemspec +30 -0
- metadata +274 -0
@@ -0,0 +1,326 @@
|
|
1
|
+
require 'worldbank_as_dataframe/queriable'
|
2
|
+
module WorldbankAsDataframe
|
3
|
+
|
4
|
+
class Country
|
5
|
+
extend WorldbankAsDataframe::Queriable
|
6
|
+
COUNTRY_ALIASES = [
|
7
|
+
['AW', 'ABW', 'aruba'],
|
8
|
+
['AF', 'AFG', 'afganistan'],
|
9
|
+
['AO', 'AGO', 'angola'],
|
10
|
+
['AI', 'AIA', 'anguilla'],
|
11
|
+
['AX', 'ALA', 'aland_islands'],
|
12
|
+
['AL', 'ALB', 'albania'],
|
13
|
+
['AD', 'AND', 'andorra'],
|
14
|
+
['AE', 'ARE', 'united_arab_emirates'],
|
15
|
+
['AR', 'ARG', 'argentina'],
|
16
|
+
['AM', 'ARM', 'armenia'],
|
17
|
+
['AS', 'ASM', 'american_samoa'],
|
18
|
+
['AQ', 'ATA', 'antarctica'],
|
19
|
+
['TF', 'ATF', 'french_southern_territories'],
|
20
|
+
['AG', 'ATG', 'antigua_and_barbuda'],
|
21
|
+
['AU', 'AUS', 'australia'],
|
22
|
+
['AT', 'AUT', 'austria'],
|
23
|
+
['AZ', 'AZE', 'azerbaijan'],
|
24
|
+
['BI', 'BDI', 'burundi'],
|
25
|
+
['BE', 'BEL', 'belgium'],
|
26
|
+
['BJ', 'BEN', 'benin'],
|
27
|
+
['BQ', 'BES', 'bonaire_saint_eustatius_and_saba'],
|
28
|
+
['BF', 'BFA', 'burkina_faso'],
|
29
|
+
['BD', 'BGD', 'bangladesh'],
|
30
|
+
['BG', 'BGR', 'bulgaria'],
|
31
|
+
['BH', 'BHR', 'bahrain'],
|
32
|
+
['BS', 'BHS', 'bahamas'],
|
33
|
+
['BA', 'BIH', 'bosnia_and_herzegovina'],
|
34
|
+
['BL', 'BLM', 'saint_barthelemy'],
|
35
|
+
['BY', 'BLR', 'belarus'],
|
36
|
+
['BZ', 'BLZ', 'belize'],
|
37
|
+
['BM', 'BMU', 'bermuda'],
|
38
|
+
['BO', 'BOL', 'plurinational_state_of_bolivia'],
|
39
|
+
['BR', 'BRA', 'brazil'],
|
40
|
+
['BB', 'BRB', 'barbados'],
|
41
|
+
['BN', 'BRN', 'brunei_darussalam'],
|
42
|
+
['BT', 'BTN', 'bhutan'],
|
43
|
+
['BV', 'BVT', 'bouvet_island'],
|
44
|
+
['BW', 'BWA', 'botswana'],
|
45
|
+
['CF', 'CAF', 'central_african_republic'],
|
46
|
+
['CA', 'CAN', 'canada'],
|
47
|
+
['CC', 'CCK', 'cocos_keeling_islands'],
|
48
|
+
['CH', 'CHE', 'switzerland'],
|
49
|
+
['CL', 'CHL', 'chile'],
|
50
|
+
['CN', 'CHN', 'china'],
|
51
|
+
['CI', 'CIV', 'cote_divoire'],
|
52
|
+
['CM', 'CMR', 'cameroon'],
|
53
|
+
['CD', 'COD', 'democratic_republic_of_the_congo'],
|
54
|
+
['CG', 'COG', 'congo'],
|
55
|
+
['CK', 'COK', 'cook_islands'],
|
56
|
+
['CO', 'COL', 'colombia'],
|
57
|
+
['KM', 'COM', 'comoros'],
|
58
|
+
['CV', 'CPV', 'cape_verde'],
|
59
|
+
['CR', 'CRI', 'costa_rica'],
|
60
|
+
['CU', 'CUB', 'cuba'],
|
61
|
+
['CW', 'CUW', 'curacao'],
|
62
|
+
['CX', 'CXR', 'christmas_island'],
|
63
|
+
['KY', 'CYM', 'cayman_islands'],
|
64
|
+
['CY', 'CYP', 'cyprus'],
|
65
|
+
['CZ', 'CZE', 'czech_republic'],
|
66
|
+
['DE', 'DEU', 'germany'],
|
67
|
+
['DJ', 'DJI', 'djibouti'],
|
68
|
+
['DM', 'DMA', 'dominca'],
|
69
|
+
['DK', 'DNK', 'denmark'],
|
70
|
+
['DO', 'DOM', 'dominican_republic'],
|
71
|
+
['DZ', 'DZA', 'algeria'],
|
72
|
+
['EC', 'ECU', 'ecuador'],
|
73
|
+
['EG', 'EGY', 'egypt'],
|
74
|
+
['ER', 'ERI', 'eritrea'],
|
75
|
+
['EH', 'ESH', 'western_sahara'],
|
76
|
+
['ES', 'ESP', 'spain'],
|
77
|
+
['EE', 'EST', 'estonia'],
|
78
|
+
['ET', 'ETH', 'ethiopia'],
|
79
|
+
['FI', 'FIN', 'finland'],
|
80
|
+
['FJ', 'FJI', 'fiji'],
|
81
|
+
['FK', 'FLK', 'falkland_islands_malvinas'],
|
82
|
+
['FR', 'FRA', 'france'],
|
83
|
+
['FO', 'FRO', 'faroe_islands'],
|
84
|
+
['FM', 'FSM', 'federated_states_of_micronesia'],
|
85
|
+
['GA', 'GAB', 'gabon'],
|
86
|
+
['GB', 'GBR', 'united_kingdom'],
|
87
|
+
['GE', 'GEO', 'georgia'],
|
88
|
+
['GG', 'GGY', 'guernsey'],
|
89
|
+
['GH', 'GHA', 'ghana'],
|
90
|
+
['GI', 'GIB', 'gibraltar'],
|
91
|
+
['GN', 'GIN', 'guinea'],
|
92
|
+
['GP', 'GLP', 'guadeloupe'],
|
93
|
+
['GM', 'GMB', 'gambia'],
|
94
|
+
['GW', 'GNB', 'guinea_bissau'],
|
95
|
+
['GQ', 'GNQ', 'equatorial_guinea'],
|
96
|
+
['GR', 'GRC', 'greece'],
|
97
|
+
['GD', 'GRD', 'grenada'],
|
98
|
+
['GL', 'GRL', 'greenland'],
|
99
|
+
['GT', 'GTM', 'guatemala'],
|
100
|
+
['GF', 'GUF', 'french_guiana'],
|
101
|
+
['GU', 'GUM', 'guam'],
|
102
|
+
['GY', 'GUY', 'guyana'],
|
103
|
+
['HK', 'HKG', 'hong_kong'],
|
104
|
+
['HM', 'HMD', 'heard_island_mcdonald_islands'],
|
105
|
+
['HN', 'HND', 'honduras'],
|
106
|
+
['HR', 'HRV', 'croatia'],
|
107
|
+
['HT', 'HTI', 'haiti'],
|
108
|
+
['HU', 'HUN', 'hungary'],
|
109
|
+
['ID', 'IDN', 'indonesia'],
|
110
|
+
['IM', 'IMN', 'isle_of_man'],
|
111
|
+
['IN', 'IND', 'india'],
|
112
|
+
['IO', 'IOT', 'british_indian_ocean_territory'],
|
113
|
+
['IE', 'IRL', 'ireland'],
|
114
|
+
['IR', 'IRN', 'islamic_republic_of_iran'],
|
115
|
+
['IQ', 'IRQ', 'iraq'],
|
116
|
+
['IS', 'ISL', 'iceland'],
|
117
|
+
['IL', 'ISR', 'israel'],
|
118
|
+
['IT', 'ITA', 'italy'],
|
119
|
+
['JM', 'JAM', 'jamaica'],
|
120
|
+
['JE', 'JEY', 'jersey'],
|
121
|
+
['JO', 'JOR', 'jordan'],
|
122
|
+
['JP', 'JPN', 'japan'],
|
123
|
+
['KZ', 'KAZ', 'kazakhstan'],
|
124
|
+
['KE', 'KEN', 'kenya'],
|
125
|
+
['KG', 'KGZ', 'kyrgyzstan'],
|
126
|
+
['KH', 'KHM', 'cambodia'],
|
127
|
+
['KI', 'KIR', 'kiribati'],
|
128
|
+
['KN', 'KNA', 'saint_kitts_and_nevis'],
|
129
|
+
['KR', 'KOR', 'republic_of_korea'],
|
130
|
+
['KW', 'KWT', 'kuwait'],
|
131
|
+
['LA', 'LAO', 'lao_peoples_democratic_republic'],
|
132
|
+
['LB', 'LBN', 'lebanon'],
|
133
|
+
['LR', 'LBR', 'liberia'],
|
134
|
+
['LY', 'LBY', 'libyan_arab_jamahiriya'],
|
135
|
+
['LC', 'LCA', 'saint_lucia'],
|
136
|
+
['LI', 'LIE', 'liechtenstein'],
|
137
|
+
['LK', 'LKA', 'sri_lanka'],
|
138
|
+
['LS', 'LSO', 'lesotho'],
|
139
|
+
['LT', 'LTU', 'lithuania'],
|
140
|
+
['LU', 'LUX', 'luxembourg'],
|
141
|
+
['LV', 'LVA', 'latvia'],
|
142
|
+
['MO', 'MAC', 'macao'],
|
143
|
+
['MF', 'MAF', 'saint_martin'],
|
144
|
+
['MA', 'MAR', 'morocco'],
|
145
|
+
['MC', 'MCO', 'monaco'],
|
146
|
+
['MD', 'MDA', 'republic_of_moldova'],
|
147
|
+
['MG', 'MDG', 'madagascar'],
|
148
|
+
['MV', 'MDV', 'maldives'],
|
149
|
+
['MX', 'MEX', 'mexico'],
|
150
|
+
['MH', 'MHL', 'marshall_islands'],
|
151
|
+
['MK', 'MKD', 'the_former_yugoslav_republic_of_macedonia'],
|
152
|
+
['ML', 'MLI', 'mali'],
|
153
|
+
['MT', 'MLT', 'malta'],
|
154
|
+
['MM', 'MMR', 'myanmar'],
|
155
|
+
['ME', 'MNE', 'montenegro'],
|
156
|
+
['MN', 'MNG', 'mongolia'],
|
157
|
+
['MP', 'MNP', 'northern_mariana_islands'],
|
158
|
+
['MZ', 'MOZ', 'mozambique'],
|
159
|
+
['MR', 'MRT', 'mauritania'],
|
160
|
+
['MS', 'MSR', 'montserrat'],
|
161
|
+
['MQ', 'MTQ', 'martinique'],
|
162
|
+
['MU', 'MUS', 'mauritius'],
|
163
|
+
['MW', 'MWI', 'malawi'],
|
164
|
+
['MY', 'MYS', 'malaysia'],
|
165
|
+
['YT', 'MYT', 'mayotte'],
|
166
|
+
['NA', 'NAM', 'namibia'],
|
167
|
+
['NC', 'NCL', 'new_caledonia'],
|
168
|
+
['NE', 'NER', 'niger'],
|
169
|
+
['NF', 'NFK', 'norfolk_island'],
|
170
|
+
['NG', 'NGA', 'nigeria'],
|
171
|
+
['NI', 'NIC', 'nicaragua'],
|
172
|
+
['NU', 'NIU', 'niue'],
|
173
|
+
['NL', 'NLD', 'netherlands'],
|
174
|
+
['NO', 'NOR', 'norway'],
|
175
|
+
['NP', 'NPL', 'nepal'],
|
176
|
+
['NR', 'NRU', 'nauru'],
|
177
|
+
['NZ', 'NZL', 'new_zealand'],
|
178
|
+
['OM', 'OMN', 'oman'],
|
179
|
+
['PK', 'PAK', 'pakistan'],
|
180
|
+
['PA', 'PAN', 'panama'],
|
181
|
+
['PN', 'PCN', 'pitcairn'],
|
182
|
+
['PE', 'PER', 'peru'],
|
183
|
+
['PH', 'PHL', 'philippines'],
|
184
|
+
['PW', 'PLW', 'palau'],
|
185
|
+
['PG', 'PNG', 'papua_new_guinea'],
|
186
|
+
['PL', 'POL', 'poland'],
|
187
|
+
['PR', 'PRI', 'puerto_rico'],
|
188
|
+
['KP', 'PRK', 'democratic_peoples_republic_of_korea'],
|
189
|
+
['PT', 'PRT', 'portugal'],
|
190
|
+
['PY', 'PRY', 'paraguay'],
|
191
|
+
['PS', 'PSE', 'occupied_palestinian_territory'],
|
192
|
+
['PF', 'PYF', 'french_polynesia'],
|
193
|
+
['QA', 'QAT', 'qatar'],
|
194
|
+
['RE', 'REU', 'reunion'],
|
195
|
+
['RO', 'ROU', 'romania'],
|
196
|
+
['RU', 'RUS', 'russian_federation'],
|
197
|
+
['RW', 'RWA', 'rwanda'],
|
198
|
+
['SA', 'SAU', 'saudi_arabia'],
|
199
|
+
['SD', 'SDN', 'sudan'],
|
200
|
+
['SN', 'SEN', 'senegal'],
|
201
|
+
['SG', 'SGP', 'singapore'],
|
202
|
+
['GS', 'SGS', 'south_georgia_and_the_south_sandwich_islands'],
|
203
|
+
['SH', 'SHN', 'saint_helena_ascension_and_tristan_da_cunha'],
|
204
|
+
['SJ', 'SJM', 'svalbard_and_jan_mayen'],
|
205
|
+
['SB', 'SLB', 'soloman_islands'],
|
206
|
+
['SL', 'SLE', 'sierra_leone'],
|
207
|
+
['SV', 'SLV', 'el_salvador'],
|
208
|
+
['SM', 'SMR', 'san_marino'],
|
209
|
+
['SO', 'SOM', 'somalia'],
|
210
|
+
['PM', 'SPM', 'saint_pierre_and_miquelon'],
|
211
|
+
['RS', 'SRB', 'serbia'],
|
212
|
+
['ST', 'STP', 'sao_tome_and_principe'],
|
213
|
+
['SR', 'SUR', 'suriname'],
|
214
|
+
['SK', 'SVK', 'slovakia'],
|
215
|
+
['SI', 'SVN', 'slovenia'],
|
216
|
+
['SE', 'SWE', 'sweden'],
|
217
|
+
['SZ', 'SWZ', 'swaziland'],
|
218
|
+
['SX', 'SXM', 'sint_maarten'],
|
219
|
+
['SC', 'SYC', 'seychelles'],
|
220
|
+
['SY', 'SYR', 'syrian_arab_republic'],
|
221
|
+
['TC', 'TCA', 'turks_caicos_islands'],
|
222
|
+
['TD', 'TCD', 'chad'],
|
223
|
+
['TG', 'TGO', 'togo'],
|
224
|
+
['TH', 'THA', 'thailand'],
|
225
|
+
['TJ', 'TJK', 'tajikistan'],
|
226
|
+
['TK', 'TKL', 'tokelau'],
|
227
|
+
['TM', 'TKM', 'turkmenistan'],
|
228
|
+
['TL', 'TLS', 'timor_leste'],
|
229
|
+
['TO', 'TON', 'tonga'],
|
230
|
+
['TT', 'TTO', 'trinidad_and_tobago'],
|
231
|
+
['TN', 'TUN', 'tunisia'],
|
232
|
+
['TR', 'TUR', 'turkey'],
|
233
|
+
['TU', 'TUV', 'tuvalu'],
|
234
|
+
['TW', 'TWN', 'taiwan_provice_of_china'],
|
235
|
+
['TZ', 'TZA', 'united_republic_of_tanzania'],
|
236
|
+
['UG', 'UGA', 'uganda'],
|
237
|
+
['UA', 'UKR', 'ukraine'],
|
238
|
+
['UM', 'UMI', 'united_states_minor_outlying_islands'],
|
239
|
+
['UY', 'URY', 'uruguay'],
|
240
|
+
['US', 'USA', 'united_states_of_america'],
|
241
|
+
['UZ', 'UZB', 'uzbekistan'],
|
242
|
+
['VC', 'VCT', 'saint_vincent_and_the_grenadines'],
|
243
|
+
['VE', 'VEN', 'bolivarian_republic_of_venezuela'],
|
244
|
+
['VG', 'VGB', 'british_virgin_islands'],
|
245
|
+
['VI', 'VIR', 'us_virgin_islands'],
|
246
|
+
['VN', 'VNM', 'viet_nam'],
|
247
|
+
['VU', 'VUT', 'vanuatu'],
|
248
|
+
['WF', 'WLF', 'wallis_and_futuna'],
|
249
|
+
['WS', 'WSM', 'samoa'],
|
250
|
+
['YE', 'YEM', 'yemen'],
|
251
|
+
['ZA', 'ZAF', 'south_africa'],
|
252
|
+
['ZM', 'ZMB', 'zambia'],
|
253
|
+
['ZW', 'ZWE', 'zimbabwe']
|
254
|
+
]
|
255
|
+
|
256
|
+
attr_reader :raw, :name, :iso2_code, :iso3_code, :region, :income_level, :lending_type, :capital, :type
|
257
|
+
|
258
|
+
def self.country_aliases
|
259
|
+
COUNTRY_ALIASES
|
260
|
+
end
|
261
|
+
|
262
|
+
def self.country
|
263
|
+
find('all').country(arg)
|
264
|
+
end
|
265
|
+
|
266
|
+
def self.indicators(arg)
|
267
|
+
find('all').indicator(arg)
|
268
|
+
end
|
269
|
+
|
270
|
+
def self.fetch(arg)
|
271
|
+
find(arg).fetch
|
272
|
+
end
|
273
|
+
|
274
|
+
def self.all
|
275
|
+
find('all')
|
276
|
+
end
|
277
|
+
|
278
|
+
def self.find(id)
|
279
|
+
id = normalize_id id
|
280
|
+
id = ensure_id id unless id =~ /all/
|
281
|
+
WorldbankAsDataframe::ParamQuery.new('country', id, self)
|
282
|
+
end
|
283
|
+
|
284
|
+
def initialize(values={})
|
285
|
+
@raw = values
|
286
|
+
@name = values['name']
|
287
|
+
@iso2_code = values['iso2Code']
|
288
|
+
@iso3_code = values['id']
|
289
|
+
@region = WorldbankAsDataframe::Region.new(values['region']) if values['region']
|
290
|
+
@income_level = WorldbankAsDataframe::IncomeLevel.new(values['incomeLevel']) if values['incomeLevel']
|
291
|
+
@lending_type = WorldbankAsDataframe::LendingType.new(values['lendingType']) if values['lendingType']
|
292
|
+
@capital = values['capitalCity']
|
293
|
+
@type = 'countries'
|
294
|
+
end
|
295
|
+
|
296
|
+
private
|
297
|
+
|
298
|
+
def self.ensure_id(id)
|
299
|
+
@id = id
|
300
|
+
if @id.length > 3
|
301
|
+
@matching = COUNTRIES.select do |country|
|
302
|
+
country[2] =~ Regexp.new(@id)
|
303
|
+
end
|
304
|
+
if @matching.length > 1
|
305
|
+
raise ArgumentError,
|
306
|
+
"More than one country code matched '#{@id}'. Perhaps you meant one of #{@matching.join(', ')}?",
|
307
|
+
caller
|
308
|
+
elsif @matching.length == 0
|
309
|
+
raise ArgumentError,
|
310
|
+
"No countries matched '#{@id}', please try again.",
|
311
|
+
caller
|
312
|
+
else
|
313
|
+
@id = @matching[0][0]
|
314
|
+
end
|
315
|
+
end
|
316
|
+
@id
|
317
|
+
end
|
318
|
+
|
319
|
+
def self.normalize_id(id)
|
320
|
+
id.gsub!(/[ -]/, '_')
|
321
|
+
id.downcase!
|
322
|
+
id
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'worldbank_as_dataframe/queriable'
|
2
|
+
module WorldbankAsDataframe
|
3
|
+
|
4
|
+
class Data
|
5
|
+
extend WorldbankAsDataframe::Queriable
|
6
|
+
attr_reader :raw, :name, :id, :value, :date, :others
|
7
|
+
|
8
|
+
def self.raw
|
9
|
+
find('all').raw
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.country(arg)
|
13
|
+
find('all').country(arg)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.fetch(arg)
|
17
|
+
find(arg).fetch
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.all
|
21
|
+
find('all')
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.find(id)
|
25
|
+
WorldbankAsDataframe::DataQuery.new('indicator', id, self)
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(values={})
|
29
|
+
@raw = values
|
30
|
+
@name = values['indicator'].delete('value')
|
31
|
+
@id = values['indicator'].delete('id')
|
32
|
+
@value = values.delete('value')
|
33
|
+
@date = values.delete('date')
|
34
|
+
values.delete('indicator')
|
35
|
+
@others = values
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_h
|
39
|
+
hdr = @name
|
40
|
+
suffix = nil
|
41
|
+
suffix = " for #{@others['country']['value']}" rescue ''
|
42
|
+
hdr += suffix
|
43
|
+
|
44
|
+
{'Timestamps' => @date, hdr => @value }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module WorldbankAsDataframe
|
2
|
+
|
3
|
+
class DataQuery < Query
|
4
|
+
|
5
|
+
def initialize(name, id, model)
|
6
|
+
super
|
7
|
+
clear_params!
|
8
|
+
end
|
9
|
+
|
10
|
+
def fetch_as_hsh
|
11
|
+
results = super
|
12
|
+
clear_params!
|
13
|
+
results
|
14
|
+
end
|
15
|
+
|
16
|
+
def fetch
|
17
|
+
require 'polars-df'
|
18
|
+
|
19
|
+
results = super
|
20
|
+
clear_params!
|
21
|
+
Polars::DataFrame.new(results.map(&:to_h))
|
22
|
+
end
|
23
|
+
|
24
|
+
def lending_type(lending_type)
|
25
|
+
ensure_unconflicting_qualifiers
|
26
|
+
parsed = indifferent_number lending_type
|
27
|
+
@param_dir = ['lendingTypes', parsed]
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def income_level(income_level)
|
32
|
+
ensure_unconflicting_qualifiers
|
33
|
+
parsed = indifferent_number income_level
|
34
|
+
@param_dir = ['incomeLevels', parsed]
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def region(regions)
|
39
|
+
ensure_unconflicting_qualifiers
|
40
|
+
parsed = indifferent_number regions
|
41
|
+
@param_dir = ['country', parsed]
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
def country(country)
|
46
|
+
ensure_unconflicting_qualifiers
|
47
|
+
parsed = indifferent_type country
|
48
|
+
parsed = ensure_country_id parsed
|
49
|
+
@param_dir = ['country', parsed]
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
def indicator(indicators)
|
54
|
+
parsed = indifferent_number indicators
|
55
|
+
@id = parsed
|
56
|
+
self
|
57
|
+
end
|
58
|
+
alias_method(:find, :indicator)
|
59
|
+
|
60
|
+
def source(sources)
|
61
|
+
ensure_unconflicting_qualifiers
|
62
|
+
parsed = indifferent_number sources
|
63
|
+
@param_dir = ['sources', parsed]
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def ensure_unconflicting_qualifiers
|
70
|
+
if @params_filled
|
71
|
+
raise ArgumentError,
|
72
|
+
"Only one of 'income_level', 'lending_type', 'country', or 'source' can be called on the same query"
|
73
|
+
end
|
74
|
+
@params_filled = true
|
75
|
+
end
|
76
|
+
|
77
|
+
def clear_params!
|
78
|
+
@param_dir = []
|
79
|
+
@params_filled = false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module WorldbankAsDataframe
|
2
|
+
|
3
|
+
class IncomeLevel
|
4
|
+
|
5
|
+
attr_reader :raw, :id, :name, :type
|
6
|
+
|
7
|
+
def self.all
|
8
|
+
find('all')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.find(id)
|
12
|
+
WorldbankAsDataframe::ParamQuery.new('incomeLevels', id, self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(values={})
|
16
|
+
@raw = values
|
17
|
+
@id = values['id']
|
18
|
+
@name = values['value']
|
19
|
+
@type = 'incomeLevels'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'worldbank_as_dataframe/queriable'
|
2
|
+
module WorldbankAsDataframe
|
3
|
+
|
4
|
+
class Indicator
|
5
|
+
extend WorldbankAsDataframe::Queriable
|
6
|
+
attr_reader :raw, :id, :name, :source, :note, :organization, :topics, :type
|
7
|
+
|
8
|
+
def self.country
|
9
|
+
find('all').country(arg)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.fetch(arg)
|
13
|
+
find(arg).fetch
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.featured
|
17
|
+
find('all').featured_indicators
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.all
|
21
|
+
find('all')
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.find(id)
|
25
|
+
WorldbankAsDataframe::ParamQuery.new('indicator', id, self)
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(values={})
|
29
|
+
@raw = values
|
30
|
+
@id = values['id']
|
31
|
+
@name = values['name']
|
32
|
+
@source = WorldbankAsDataframe::Source.new(values['source'])
|
33
|
+
@note = values['sourceNote']
|
34
|
+
@organization = values['sourceOrganization']
|
35
|
+
@topics = []
|
36
|
+
values['topics'].each do |topic|
|
37
|
+
@topics << WorldbankAsDataframe::Topic.new(topic)
|
38
|
+
end
|
39
|
+
@type = 'indicator'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module WorldbankAsDataframe
|
2
|
+
|
3
|
+
class LendingType
|
4
|
+
|
5
|
+
attr_reader :raw, :id, :name, :type
|
6
|
+
|
7
|
+
def self.all
|
8
|
+
find('all')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.find(id)
|
12
|
+
WorldbankAsDataframe::ParamQuery.new('lendingTypes', id, self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(values={})
|
16
|
+
@raw = values
|
17
|
+
@id = values['id']
|
18
|
+
@name = values['value']
|
19
|
+
@type = 'lendingTypes'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module WorldbankAsDataframe
|
2
|
+
|
3
|
+
class ParamQuery < Query
|
4
|
+
|
5
|
+
def initialize(name, id, model)
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def lending_type(lending_type)
|
10
|
+
parsed = indifferent_number lending_type
|
11
|
+
@query[:params].merge!({:lendingTypes => parsed})
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def income_level(income_levels)
|
16
|
+
parsed = indifferent_number income_levels
|
17
|
+
@query[:params].merge!({:incomeLevels => parsed})
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def region(regions)
|
22
|
+
parsed = indifferent_number regions
|
23
|
+
@query[:params].merge!({:country => parsed})
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def country(country)
|
28
|
+
parsed = indifferent_type country
|
29
|
+
parsed = ensure_country_id parsed
|
30
|
+
@query[:params].merge!({:country => parsed})
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def indicator(indicators)
|
35
|
+
parsed = indifferent_number indicators
|
36
|
+
@query[:params].merge!({:indicator => parsed})
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def featured_indicators
|
41
|
+
@query[:params].merge!({:featured => 1})
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
def source(sources)
|
46
|
+
parsed = indifferent_number sources
|
47
|
+
@query[:params].merge!({:sources => parsed})
|
48
|
+
self
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module WorldbankAsDataframe
|
2
|
+
module Queriable
|
3
|
+
def id(arg)
|
4
|
+
find('all').id(arg)
|
5
|
+
end
|
6
|
+
|
7
|
+
def most_recent_values(arg)
|
8
|
+
find('all').most_recent_values(arg)
|
9
|
+
end
|
10
|
+
|
11
|
+
def page(arg)
|
12
|
+
find('all').page(arg)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.per_page(arg)
|
16
|
+
find('all').per_page(arg)
|
17
|
+
end
|
18
|
+
|
19
|
+
def language(arg)
|
20
|
+
find('all').language(arg)
|
21
|
+
end
|
22
|
+
|
23
|
+
def format(arg)
|
24
|
+
find('all').format(arg)
|
25
|
+
end
|
26
|
+
|
27
|
+
def income_level(arg)
|
28
|
+
find('all').income_level(arg)
|
29
|
+
end
|
30
|
+
|
31
|
+
def lending_type(arg)
|
32
|
+
find('all').lending_type(arg)
|
33
|
+
end
|
34
|
+
|
35
|
+
def region(arg)
|
36
|
+
find('all').region(arg)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|