carmen-demonyms 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dba5542a02682642e8466c66fb069e1a91a2a476
4
- data.tar.gz: 87fa03901d4ca94e07e27abdca1499a9fbf5e78a
3
+ metadata.gz: 08d4d490c9ff18b2b5ad3990278953512c3f8116
4
+ data.tar.gz: 45056a83e4a046f47e33400ab2755367abd9ba96
5
5
  SHA512:
6
- metadata.gz: ac586d40b92e7236915beed84552fb6e8c10bb3ece43694b8526397fae2fd24573c1bd7b521b2cbd2d98cf5dcfde16031e22f884df789cef3ff1957b1a462593
7
- data.tar.gz: ff1c12d4107b719052004d4d5b789779d019a3f8c294f8c83a94906614b363a9ba9008ee0bd6417dc6fee38b607fdc04f924602a85c5649d4dc07bb691fdb501
6
+ metadata.gz: 58f6f2b9d261f81d4ce03a0dd89ffe5cf5eb4c6198773de84ff40969fdbf82e9d55da8c9686d1eb2a7d70f338c59f92aabb766cc34514e5837c23581cc1740ce
7
+ data.tar.gz: e6f401a726038027ed19f1af217f44c576e03e6f30f649113f937893fdcc830137f0c55bff8b2c7396c4318e2ac5c0840dfb58aba56517fdcd9638a01ca14947
@@ -1,5 +1,5 @@
1
1
  module Carmen
2
2
  module Demonyms
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,501 @@
1
+ ---
2
+ en:
3
+ world:
4
+ ad:
5
+ demonym: Andorran
6
+ ae:
7
+ demonym: Emirati
8
+ af:
9
+ demonym: Afghan
10
+ ag:
11
+ demonym: Antiguan
12
+ ai:
13
+ demonym: Anguillan
14
+ al:
15
+ demonym: Albanian
16
+ am:
17
+ demonym: Armenian
18
+ ao:
19
+ demonym: Angolan
20
+ aq:
21
+ demonym:
22
+ ar:
23
+ demonym: Argentine
24
+ as:
25
+ demonym: American Samoan
26
+ at:
27
+ demonym: Austrian
28
+ au:
29
+ demonym: Australian
30
+ aw:
31
+ demonym: Aruban
32
+ ax:
33
+ demonym:
34
+ az:
35
+ demonym: Azerbaijani
36
+ ba:
37
+ demonym: Bosnian
38
+ bb:
39
+ demonym: Barbadian
40
+ bd:
41
+ demonym: Bangladeshi
42
+ be:
43
+ demonym: Belgian
44
+ bf:
45
+ demonym: Burkinabè
46
+ bg:
47
+ demonym: Bulgarian
48
+ bh:
49
+ demonym: Bahraini
50
+ bi:
51
+ demonym: Burundian
52
+ bj:
53
+ demonym: Beninese
54
+ bl:
55
+ demonym:
56
+ bm:
57
+ demonym: Bermudian
58
+ bn:
59
+ demonym:
60
+ bo:
61
+ demonym:
62
+ bq:
63
+ demonym:
64
+ br:
65
+ demonym: Brazilian
66
+ bs:
67
+ demonym: Bahamian
68
+ bt:
69
+ demonym: Bhutanese
70
+ bv:
71
+ demonym:
72
+ bw:
73
+ demonym: Motswana
74
+ by:
75
+ demonym: Belarusian
76
+ bz:
77
+ demonym: Belizean
78
+ ca:
79
+ demonym: Canadian
80
+ cc:
81
+ demonym: Cocos Island
82
+ cd:
83
+ demonym:
84
+ cf:
85
+ demonym: Central African
86
+ cg:
87
+ demonym: Congolese
88
+ ch:
89
+ demonym: Swiss
90
+ ci:
91
+ demonym:
92
+ ck:
93
+ demonym: Cook Island
94
+ cl:
95
+ demonym: Chilean
96
+ cm:
97
+ demonym: Cameroonian
98
+ cn:
99
+ demonym: Chinese
100
+ co:
101
+ demonym: Colombian
102
+ cr:
103
+ demonym: Costa Rican
104
+ cu:
105
+ demonym: Cuban
106
+ cv:
107
+ demonym: Cape Verdean
108
+ cw:
109
+ demonym:
110
+ cx:
111
+ demonym: Christmas Island
112
+ cy:
113
+ demonym: Cypriot
114
+ cz:
115
+ demonym: Czech
116
+ de:
117
+ demonym: German
118
+ dj:
119
+ demonym: Djiboutian
120
+ dk:
121
+ demonym: Danish
122
+ dm:
123
+ demonym: Dominican
124
+ do:
125
+ demonym: Dominican
126
+ dz:
127
+ demonym: Algerian
128
+ ec:
129
+ demonym: Ecuadorian
130
+ ee:
131
+ demonym: Estonian
132
+ eg:
133
+ demonym: Egyptian
134
+ eh:
135
+ demonym: Sahraw
136
+ er:
137
+ demonym: Eritrean
138
+ es:
139
+ demonym: Spanish
140
+ et:
141
+ demonym: Ethiopian
142
+ fi:
143
+ demonym: Finnish
144
+ fj:
145
+ demonym: Fijian
146
+ fk:
147
+ demonym:
148
+ fm:
149
+ demonym:
150
+ fo:
151
+ demonym: Faroese
152
+ fr:
153
+ demonym: French
154
+ ga:
155
+ demonym: Gabonese
156
+ gb:
157
+ demonym: British
158
+ gd:
159
+ demonym: Grenadian
160
+ ge:
161
+ demonym: Georgian
162
+ gf:
163
+ demonym: French Guianese
164
+ gg:
165
+ demonym:
166
+ gh:
167
+ demonym: Ghanaian
168
+ gi:
169
+ demonym: Gibraltar
170
+ gl:
171
+ demonym: Greenlandic
172
+ gm:
173
+ demonym: Gambian
174
+ gn:
175
+ demonym: Equatorial Guinean
176
+ gp:
177
+ demonym: Guadeloupe
178
+ gq:
179
+ demonym: Equatorial Guinean
180
+ gr:
181
+ demonym: Greek
182
+ gs:
183
+ demonym:
184
+ gt:
185
+ demonym: Guatemalan
186
+ gu:
187
+ demonym: Guamanian
188
+ gw:
189
+ demonym:
190
+ gy:
191
+ demonym: Guyanese
192
+ hk:
193
+ demonym: Hong Kong
194
+ hm:
195
+ demonym:
196
+ hn:
197
+ demonym: Honduran
198
+ hr:
199
+ demonym: Croatian
200
+ ht:
201
+ demonym: Haitian
202
+ hu:
203
+ demonym: Magyar
204
+ id:
205
+ demonym: Indonesian
206
+ ie:
207
+ demonym: Irish
208
+ il:
209
+ demonym: Israeli
210
+ im:
211
+ demonym: Manx
212
+ in:
213
+ demonym: Indian
214
+ io:
215
+ demonym:
216
+ iq:
217
+ demonym: Iraqi
218
+ ir:
219
+ demonym:
220
+ is:
221
+ demonym: Icelandic
222
+ it:
223
+ demonym: Italic
224
+ je:
225
+ demonym:
226
+ jm:
227
+ demonym: Jamaican
228
+ jo:
229
+ demonym: Jordanian
230
+ jp:
231
+ demonym: Japanese
232
+ ke:
233
+ demonym: Kenyan
234
+ kg:
235
+ demonym: Kyrgyzstani
236
+ kh:
237
+ demonym: Cambodian
238
+ ki:
239
+ demonym: I-Kiribati
240
+ km:
241
+ demonym: Comorian
242
+ kn:
243
+ demonym: Kittitian
244
+ kp:
245
+ demonym:
246
+ kr:
247
+ demonym:
248
+ kw:
249
+ demonym: Kuwaiti
250
+ ky:
251
+ demonym: Caymanian
252
+ kz:
253
+ demonym: Kazakh
254
+ la:
255
+ demonym:
256
+ lb:
257
+ demonym: Lebanese
258
+ lc:
259
+ demonym: St. Lucian
260
+ li:
261
+ demonym: Liechtenstein
262
+ lk:
263
+ demonym: Sri Lankan
264
+ lr:
265
+ demonym: Liberian
266
+ ls:
267
+ demonym: Basotho
268
+ lt:
269
+ demonym: Lithuanian
270
+ lu:
271
+ demonym: Luxembourg
272
+ lv:
273
+ demonym: Latvian
274
+ ly:
275
+ demonym: Libyan
276
+ ma:
277
+ demonym: Moroccan
278
+ mc:
279
+ demonym: Monégasque
280
+ md:
281
+ demonym:
282
+ me:
283
+ demonym: Montenegrin
284
+ mf:
285
+ demonym:
286
+ mg:
287
+ demonym: Malagasy
288
+ mh:
289
+ demonym: Marshallese
290
+ mk:
291
+ demonym:
292
+ ml:
293
+ demonym: Malian
294
+ mm:
295
+ demonym:
296
+ mn:
297
+ demonym: Mongolian
298
+ mo:
299
+ demonym:
300
+ mp:
301
+ demonym:
302
+ mq:
303
+ demonym: Martiniquais
304
+ mr:
305
+ demonym: Mauritanian
306
+ ms:
307
+ demonym: Montserratian
308
+ mt:
309
+ demonym: Maltese
310
+ mu:
311
+ demonym: Mauritian
312
+ mv:
313
+ demonym: Maldivian
314
+ mw:
315
+ demonym: Malawian
316
+ mx:
317
+ demonym: Mexican
318
+ my:
319
+ demonym: Malaysian
320
+ mz:
321
+ demonym: Mozambican
322
+ na:
323
+ demonym: Namibian
324
+ nc:
325
+ demonym: New Caledonian
326
+ ne:
327
+ demonym: Nigerien
328
+ nf:
329
+ demonym:
330
+ ng:
331
+ demonym: Nigerian
332
+ ni:
333
+ demonym: Nicaraguan
334
+ nl:
335
+ demonym: Dutch
336
+ 'no':
337
+ demonym: Norwegian
338
+ np:
339
+ demonym: Nepali
340
+ nr:
341
+ demonym: Nauruan
342
+ nu:
343
+ demonym: Niuean
344
+ nz:
345
+ demonym: New Zealand
346
+ om:
347
+ demonym: Omani
348
+ pa:
349
+ demonym: Panamanian
350
+ pe:
351
+ demonym: Peruvian
352
+ pf:
353
+ demonym: French Polynesian
354
+ pg:
355
+ demonym: Papua New Guinean
356
+ ph:
357
+ demonym: Philippine
358
+ pk:
359
+ demonym: Pakistani
360
+ pl:
361
+ demonym: Polish
362
+ pm:
363
+ demonym:
364
+ pn:
365
+ demonym: Pitcairn Island
366
+ pr:
367
+ demonym: Puerto Rican
368
+ ps:
369
+ demonym:
370
+ pt:
371
+ demonym: Portuguese
372
+ pw:
373
+ demonym: Palauan
374
+ py:
375
+ demonym: Paraguayan
376
+ qa:
377
+ demonym: Qatari
378
+ re:
379
+ demonym: Réunionese
380
+ ro:
381
+ demonym: Romanian
382
+ rs:
383
+ demonym: Serbian
384
+ ru:
385
+ demonym:
386
+ rw:
387
+ demonym: Rwandan
388
+ sa:
389
+ demonym: Saudi
390
+ sb:
391
+ demonym: Solomon Island
392
+ sc:
393
+ demonym: Seychellois
394
+ sd:
395
+ demonym: South Sudanese
396
+ se:
397
+ demonym: Swedish
398
+ sg:
399
+ demonym: Singaporean
400
+ sh:
401
+ demonym:
402
+ si:
403
+ demonym: Slovenian,
404
+ sj:
405
+ demonym:
406
+ sk:
407
+ demonym: Slovak
408
+ sl:
409
+ demonym: Sierra Leonean
410
+ sm:
411
+ demonym: Sammarinese
412
+ sn:
413
+ demonym: Senegalese
414
+ so:
415
+ demonym: Somali
416
+ sr:
417
+ demonym: Surinamese
418
+ ss:
419
+ demonym: South Sudanese
420
+ st:
421
+ demonym:
422
+ sv:
423
+ demonym: Salvadoran
424
+ sx:
425
+ demonym:
426
+ sy:
427
+ demonym:
428
+ sz:
429
+ demonym: Swazi
430
+ tc:
431
+ demonym: none
432
+ td:
433
+ demonym: Chadian
434
+ tf:
435
+ demonym:
436
+ tg:
437
+ demonym: Togolese
438
+ th:
439
+ demonym: Thai
440
+ tj:
441
+ demonym: Tajikistani
442
+ tk:
443
+ demonym:
444
+ tl:
445
+ demonym:
446
+ tm:
447
+ demonym: Turkmen
448
+ tn:
449
+ demonym: Tunisian
450
+ to:
451
+ demonym: Tongan
452
+ tr:
453
+ demonym: Turkish
454
+ tt:
455
+ demonym: Trinidadian
456
+ tv:
457
+ demonym: Tuvaluan
458
+ tw:
459
+ demonym:
460
+ tz:
461
+ demonym:
462
+ ua:
463
+ demonym: Ukrainian
464
+ ug:
465
+ demonym: Ugandan
466
+ um:
467
+ demonym:
468
+ us:
469
+ demonym: American
470
+ uy:
471
+ demonym: Uruguayan
472
+ uz:
473
+ demonym: Uzbekistani
474
+ va:
475
+ demonym:
476
+ vc:
477
+ demonym: St. Vincentian
478
+ ve:
479
+ demonym:
480
+ vg:
481
+ demonym:
482
+ vi:
483
+ demonym:
484
+ vn:
485
+ demonym:
486
+ vu:
487
+ demonym: Ni-Vanuatu
488
+ wf:
489
+ demonym: Wallisian
490
+ ws:
491
+ demonym: American Samoan
492
+ ye:
493
+ demonym: Yemeni
494
+ yt:
495
+ demonym: Mahoran
496
+ za:
497
+ demonym: South African
498
+ zm:
499
+ demonym: Zambian
500
+ zw:
501
+ demonym: Zimbabwean
@@ -0,0 +1,132 @@
1
+ require 'net/http'
2
+ require 'nokogiri'
3
+ require 'yaml'
4
+
5
+ YAML::ENGINE.yamler = 'psych'
6
+
7
+ class DemonymsData
8
+ def self.data_dir
9
+ @data_dir ||= File.expand_path('../../tmp', __FILE__)
10
+ end
11
+
12
+ def self.wiki_domain(locale='en')
13
+ "#{locale}.wikipedia.org"
14
+ end
15
+
16
+ def self.data_urls
17
+ { primary: "/wiki/List_of_adjectival_and_demonymic_forms_of_place_names",
18
+ countries: "/wiki/List_of_adjectival_and_demonymic_forms_for_countries_and_nations",
19
+ us_states: "/wiki/List_of_demonyms_for_U.S._states" }
20
+ end
21
+
22
+ def self.download
23
+ self.data_urls.each_pair do |file_name, path|
24
+ dest = File.join(data_dir, "#{file_name}.html")
25
+ data = Net::HTTP.get(wiki_domain, path)
26
+ mode = "w+"
27
+
28
+ File.open(dest, mode) { |f| f << data }
29
+ end
30
+ end
31
+
32
+ def data_file(name)
33
+ File.read(File.join(self.class.data_dir, "#{name}.html"))
34
+ end
35
+
36
+ attr_accessor :primary, :countries, :us_states
37
+ def initialize
38
+ @primary = Nokogiri::HTML.parse(data_file(:primary))
39
+ @countries = Nokogiri::HTML.parse(data_file(:countries))
40
+ @us_states = Nokogiri::HTML.parse(data_file(:us_states))
41
+ end
42
+ end
43
+
44
+ class FindDemonym
45
+ attr_accessor :data
46
+ def initialize(data)
47
+ @data = data
48
+ end
49
+
50
+ def for_country_name(country_name)
51
+ clean_country_name = country_name #.gsub(/[^a-zA-z0-9]/, '')
52
+ country_link = data.countries.css("a[title*='#{clean_country_name}']").first
53
+
54
+ if country_link.nil?
55
+ puts "Couldn't find matching link for #{country_name} (#{clean_country_name})"
56
+ return nil
57
+ end
58
+
59
+ if row = country_link.ancestors("tr").first
60
+ columns = row.css('td')
61
+
62
+ if columns[1].respond_to?(:css)
63
+ link = columns[1].css("a").first
64
+
65
+ if link.nil?
66
+ first_word_in_column = columns[1].text.split(' ').first
67
+ return first_word_in_column
68
+ else
69
+ return link.text
70
+ end
71
+ else
72
+ puts "Couldn't find adjective column for #{country_name} (#{clean_country_name})"
73
+ return nil
74
+ end
75
+ else
76
+ puts "Couldn't traverse to a row for #{country_name} (#{clean_country_name})"
77
+ return nil
78
+ end
79
+
80
+ return nil
81
+ rescue
82
+ puts "Error while finding demonym for country: #{country_name}"
83
+ puts $!
84
+ return nil
85
+ end
86
+ end
87
+
88
+ class WorldData
89
+ attr_accessor :data, :find_demonym
90
+
91
+ def initialize
92
+ @data = { 'en' => { 'world' => {} } }
93
+ demonym_data = DemonymsData.new
94
+ @find_demonym = FindDemonym.new(demonym_data)
95
+ end
96
+
97
+ def add_demonyms
98
+ Carmen::Country.all.each do |country|
99
+ demonym = find_demonym.for_country_name(country.name)
100
+ @data['en']['world'][country.code.downcase] ||= {}
101
+ @data['en']['world'][country.code.downcase]['demonym'] = demonym
102
+ end
103
+ end
104
+
105
+ def write
106
+ path = File.expand_path("../../locale/en/world.yml", __FILE__)
107
+ File.open(path, 'w+') { |f| f << @data.to_yaml }
108
+ end
109
+
110
+ def add_demonyms!
111
+ add_demonyms
112
+ write
113
+ end
114
+
115
+ def countries
116
+ @data['en']['world'].values
117
+ end
118
+
119
+ def countries_without_demonym
120
+ countries.select { |v| v['demonym'].nil? }
121
+ end
122
+
123
+ def count_countries_without_demonym
124
+ countries_without_demonym.count
125
+ end
126
+
127
+ def count_countries
128
+ countries.count
129
+ @data['en']['world'].values.count
130
+ end
131
+ end
132
+
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Carmen::Country do
4
+ describe "basic attributes" do
5
+ before do
6
+ @us = Carmen::Country.coded('us')
7
+ end
8
+
9
+ it "has a demonym" do
10
+ expect(@us.demonym).to eq("American")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ require 'carmen/demonyms'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carmen-demonyms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Morris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-08 00:00:00.000000000 Z
11
+ date: 2013-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carmen
@@ -95,6 +95,10 @@ files:
95
95
  - carmen-demonyms.gemspec
96
96
  - lib/carmen/demonyms.rb
97
97
  - lib/carmen/demonyms/version.rb
98
+ - locale/en/world.yml
99
+ - script/import.rb
100
+ - spec/carmen/country_spec.rb
101
+ - spec/spec_helper.rb
98
102
  homepage: ''
99
103
  licenses:
100
104
  - MIT
@@ -119,4 +123,6 @@ rubygems_version: 2.0.0
119
123
  signing_key:
120
124
  specification_version: 4
121
125
  summary: Add demonums to Carmen::Country
122
- test_files: []
126
+ test_files:
127
+ - spec/carmen/country_spec.rb
128
+ - spec/spec_helper.rb