countryconvert 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/countryconvert.rb +24 -0
  3. data/lib/isocodes.json +249 -0
  4. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e58ff625a12840d74008039d751ca110fec2c641
4
+ data.tar.gz: 71e4440907a54920bb5e984b11b9a667de071cb0
5
+ SHA512:
6
+ metadata.gz: ceaf2de5304d88bdbbd1445c0896d29666a868269b71ac035869e8999b116851424ed5501ae58f1de7e60b30da36c144516f235aed75afe9b00e2d7ad32ff480
7
+ data.tar.gz: 89f741be3ebd8f49d6de2d12063166c73c4cd5717e0c595a0353ae3c4c1459bf0a4ba3712481c8d40fa45c24b2b2a3a51187e4c5ec3914b7e031b372efb63ee5
@@ -0,0 +1,24 @@
1
+ require 'json'
2
+
3
+ class CountryConvert
4
+ def initialize(input, countryfield)
5
+ @input = JSON.parse(input)
6
+ @countryfield = countryfield
7
+ @isocodes = JSON.parse(File.read("isocodes.json"))
8
+ end
9
+
10
+ def convert
11
+ finaldata = Array.new
12
+ @input.each do |f|
13
+ if @isocodes[f[@countryfield].upcase]
14
+ threeletter = @isocodes[f[@countryfield].upcase]
15
+ f[@countryfield] = threeletter
16
+ finaldata.push(f)
17
+ end
18
+ end
19
+ return JSON.pretty_generate(finaldata)
20
+ end
21
+ end
22
+
23
+ c = CountryConvert.new(File.read("filtered.json"), "country")
24
+ puts c.convert
data/lib/isocodes.json ADDED
@@ -0,0 +1,249 @@
1
+ {
2
+ "AF": "AFG",
3
+ "AX": "ALA",
4
+ "AL": "ALB",
5
+ "DZ": "DZA",
6
+ "AS": "ASM",
7
+ "AD": "AND",
8
+ "AO": "AGO",
9
+ "AI": "AIA",
10
+ "AQ": "ATA",
11
+ "AG": "ATG",
12
+ "AR": "ARG",
13
+ "AM": "ARM",
14
+ "AW": "ABW",
15
+ "AU": "AUS",
16
+ "AT": "AUT",
17
+ "AZ": "AZE",
18
+ "BS": "BHS",
19
+ "BH": "BHR",
20
+ "BD": "BGD",
21
+ "BB": "BRB",
22
+ "BY": "BLR",
23
+ "BE": "BEL",
24
+ "BZ": "BLZ",
25
+ "BJ": "BEN",
26
+ "BM": "BMU",
27
+ "BT": "BTN",
28
+ "BO": "BOL",
29
+ "BA": "BIH",
30
+ "BW": "BWA",
31
+ "BV": "BVT",
32
+ "BR": "BRA",
33
+ "VG": "VGB",
34
+ "IO": "IOT",
35
+ "BN": "BRN",
36
+ "BG": "BGR",
37
+ "BF": "BFA",
38
+ "BI": "BDI",
39
+ "KH": "KHM",
40
+ "CM": "CMR",
41
+ "CA": "CAN",
42
+ "CV": "CPV",
43
+ "KY": "CYM",
44
+ "CF": "CAF",
45
+ "TD": "TCD",
46
+ "CL": "CHL",
47
+ "CN": "CHN",
48
+ "HK": "HKG",
49
+ "MO": "MAC",
50
+ "CX": "CXR",
51
+ "CC": "CCK",
52
+ "CO": "COL",
53
+ "KM": "COM",
54
+ "CG": "COG",
55
+ "CD": "COD",
56
+ "CK": "COK",
57
+ "CR": "CRI",
58
+ "CI": "CIV",
59
+ "HR": "HRV",
60
+ "CU": "CUB",
61
+ "CY": "CYP",
62
+ "CZ": "CZE",
63
+ "DK": "DNK",
64
+ "DJ": "DJI",
65
+ "DM": "DMA",
66
+ "DO": "DOM",
67
+ "EC": "ECU",
68
+ "EG": "EGY",
69
+ "SV": "SLV",
70
+ "GQ": "GNQ",
71
+ "ER": "ERI",
72
+ "EE": "EST",
73
+ "ET": "ETH",
74
+ "FK": "FLK",
75
+ "FO": "FRO",
76
+ "FJ": "FJI",
77
+ "FI": "FIN",
78
+ "FR": "FRA",
79
+ "GF": "GUF",
80
+ "PF": "PYF",
81
+ "TF": "ATF",
82
+ "GA": "GAB",
83
+ "GM": "GMB",
84
+ "GE": "GEO",
85
+ "DE": "DEU",
86
+ "GH": "GHA",
87
+ "GI": "GIB",
88
+ "GR": "GRC",
89
+ "GL": "GRL",
90
+ "GD": "GRD",
91
+ "GP": "GLP",
92
+ "GU": "GUM",
93
+ "GT": "GTM",
94
+ "GG": "GGY",
95
+ "GN": "GIN",
96
+ "GW": "GNB",
97
+ "GY": "GUY",
98
+ "HT": "HTI",
99
+ "HM": "HMD",
100
+ "VA": "VAT",
101
+ "HN": "HND",
102
+ "HU": "HUN",
103
+ "IS": "ISL",
104
+ "IN": "IND",
105
+ "ID": "IDN",
106
+ "IR": "IRN",
107
+ "IQ": "IRQ",
108
+ "IE": "IRL",
109
+ "IM": "IMN",
110
+ "IL": "ISR",
111
+ "IT": "ITA",
112
+ "JM": "JAM",
113
+ "JP": "JPN",
114
+ "JE": "JEY",
115
+ "JO": "JOR",
116
+ "KZ": "KAZ",
117
+ "KE": "KEN",
118
+ "KI": "KIR",
119
+ "KP": "PRK",
120
+ "KR": "KOR",
121
+ "KW": "KWT",
122
+ "KG": "KGZ",
123
+ "LA": "LAO",
124
+ "LV": "LVA",
125
+ "LB": "LBN",
126
+ "LS": "LSO",
127
+ "LR": "LBR",
128
+ "LY": "LBY",
129
+ "LI": "LIE",
130
+ "LT": "LTU",
131
+ "LU": "LUX",
132
+ "MK": "MKD",
133
+ "MG": "MDG",
134
+ "MW": "MWI",
135
+ "MY": "MYS",
136
+ "MV": "MDV",
137
+ "ML": "MLI",
138
+ "MT": "MLT",
139
+ "MH": "MHL",
140
+ "MQ": "MTQ",
141
+ "MR": "MRT",
142
+ "MU": "MUS",
143
+ "YT": "MYT",
144
+ "MX": "MEX",
145
+ "FM": "FSM",
146
+ "MD": "MDA",
147
+ "MC": "MCO",
148
+ "MN": "MNG",
149
+ "ME": "MNE",
150
+ "MS": "MSR",
151
+ "MA": "MAR",
152
+ "MZ": "MOZ",
153
+ "MM": "MMR",
154
+ "NA": "NAM",
155
+ "NR": "NRU",
156
+ "NP": "NPL",
157
+ "NL": "NLD",
158
+ "AN": "ANT",
159
+ "NC": "NCL",
160
+ "NZ": "NZL",
161
+ "NI": "NIC",
162
+ "NE": "NER",
163
+ "NG": "NGA",
164
+ "NU": "NIU",
165
+ "NF": "NFK",
166
+ "MP": "MNP",
167
+ "NO": "NOR",
168
+ "OM": "OMN",
169
+ "PK": "PAK",
170
+ "PW": "PLW",
171
+ "PS": "PSE",
172
+ "PA": "PAN",
173
+ "PG": "PNG",
174
+ "PY": "PRY",
175
+ "PE": "PER",
176
+ "PH": "PHL",
177
+ "PN": "PCN",
178
+ "PL": "POL",
179
+ "PT": "PRT",
180
+ "PR": "PRI",
181
+ "QA": "QAT",
182
+ "RE": "REU",
183
+ "RO": "ROU",
184
+ "RU": "RUS",
185
+ "RW": "RWA",
186
+ "BL": "BLM",
187
+ "SH": "SHN",
188
+ "KN": "KNA",
189
+ "LC": "LCA",
190
+ "MF": "MAF",
191
+ "PM": "SPM",
192
+ "VC": "VCT",
193
+ "WS": "WSM",
194
+ "SM": "SMR",
195
+ "ST": "STP",
196
+ "SA": "SAU",
197
+ "SN": "SEN",
198
+ "RS": "SRB",
199
+ "SC": "SYC",
200
+ "SL": "SLE",
201
+ "SG": "SGP",
202
+ "SK": "SVK",
203
+ "SI": "SVN",
204
+ "SB": "SLB",
205
+ "SO": "SOM",
206
+ "ZA": "ZAF",
207
+ "GS": "SGS",
208
+ "SS": "SSD",
209
+ "ES": "ESP",
210
+ "LK": "LKA",
211
+ "SD": "SDN",
212
+ "SR": "SUR",
213
+ "SJ": "SJM",
214
+ "SZ": "SWZ",
215
+ "SE": "SWE",
216
+ "CH": "CHE",
217
+ "SY": "SYR",
218
+ "TW": "TWN",
219
+ "TJ": "TJK",
220
+ "TZ": "TZA",
221
+ "TH": "THA",
222
+ "TL": "TLS",
223
+ "TG": "TGO",
224
+ "TK": "TKL",
225
+ "TO": "TON",
226
+ "TT": "TTO",
227
+ "TN": "TUN",
228
+ "TR": "TUR",
229
+ "TM": "TKM",
230
+ "TC": "TCA",
231
+ "TV": "TUV",
232
+ "UG": "UGA",
233
+ "UA": "UKR",
234
+ "AE": "ARE",
235
+ "GB": "GBR",
236
+ "US": "USA",
237
+ "UM": "UMI",
238
+ "UY": "URY",
239
+ "UZ": "UZB",
240
+ "VU": "VUT",
241
+ "VE": "VEN",
242
+ "VN": "VNM",
243
+ "VI": "VIR",
244
+ "WF": "WLF",
245
+ "EH": "ESH",
246
+ "YE": "YEM",
247
+ "ZM": "ZMB",
248
+ "ZW": "ZWE"
249
+ }
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: countryconvert
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - M. C. McGrath
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Converts 2-char ISO country codes to 3-char.
14
+ email: shidash@shidash.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/countryconvert.rb
20
+ - lib/isocodes.json
21
+ homepage: https://github.com/TransparencyToolkit/CountryConvert
22
+ licenses:
23
+ - GPL
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.14
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Converts country codes
45
+ test_files: []
46
+ has_rdoc: