normalize_country 0.3.1 → 0.3.3

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
  SHA256:
3
- metadata.gz: 6124424b5e181869babd13d860f376b0f50f556897a1d9eb2d81137d12a85971
4
- data.tar.gz: d0459074064cdcf9e8c9aa6a20f47a15b750be93b11406faccf281990dc2572a
3
+ metadata.gz: 793c9aaa61fc028c685a5a27681a670e12675e3f2d5db2bb4343167da1d24d94
4
+ data.tar.gz: 3a8c27532a071ec3baf5114a0ff1c35c643b85944fc45f0cb69586261eb1616c
5
5
  SHA512:
6
- metadata.gz: eb739c3d7b976793f8b479d4e271a704733d85183c3c55ea3b9e768b03c8992a8c5ed5fdc9d08a03e14757ae4ae5df821f0d5a671bda1a04d7acdf2f419583d9
7
- data.tar.gz: bfdedc36669f192bd2c2efc85fd51e7b99340b14f614e2f6ffe8f726a0db29989dcc699c0fd4d41bb0f288487b4325e1474e41212604d6268824597754620743
6
+ metadata.gz: 800a8cd65c7ed894a1af4950e03e795a86a2debbec7641aba2d676d6ebd99061a28e0672590d6ce087078813ac365ef1eff3f4a19adbb925cc8d7b8022a7fd98
7
+ data.tar.gz: ec34c172d11d352a1107254f9e9382a8a6e50538cf6cdf4b9a354cb751d6f8cce1b422900182dc530ff051fd6f9e08b2093ba5f5571c43a8c0b1b765222840f6
data/README.rdoc CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  Convert country names and codes to a standard.
4
4
 
5
- {<img src="https://travis-ci.org/sshaw/normalize_country.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/sshaw/normalize_country]
6
- {<img src="https://codeclimate.com/github/sshaw/normalize_country.svg" />}[https://codeclimate.com/github/sshaw/normalize_country]
5
+ {<img src="https://github.com/sshaw/normalize_country/actions/workflows/ci.yml/badge.svg" alt="Build Status" />}[https://github.com/sshaw/normalize_country]
7
6
 
8
7
  === Overview
9
8
 
@@ -59,6 +58,11 @@ will convert to/from the following:
59
58
 
60
59
  A list of valid formats can be obtained by calling +NormalizeCountry.formats+.
61
60
 
61
+ === Custom Database
62
+
63
+ Set the +NORMALIZE_COUNTRY_DB+ environment variable.
64
+ See <code>lib/normalize_country/countries/en.yml</code> for the expected format.
65
+
62
66
  === Obtaining an Array or Hash
63
67
 
64
68
  NormalizeCountry.to_a # Defaults to NormalizeCountry.to
@@ -172,6 +172,8 @@ AW:
172
172
  emoji: "\U0001F1E6\U0001F1FC"
173
173
  shortcode: ":flag-aw:"
174
174
  AX:
175
+ aliases:
176
+ - Aland Islands
175
177
  alpha2: AX
176
178
  alpha3: ALA
177
179
  fifa:
@@ -196,6 +198,7 @@ AZ:
196
198
  BA:
197
199
  aliases:
198
200
  - Bosnia-Herzegovina
201
+ - Bosnia Herzegovina
199
202
  alpha2: BA
200
203
  alpha3: BIH
201
204
  fifa: BIH
@@ -299,6 +302,9 @@ BL:
299
302
  - Saint Barts
300
303
  - St. Barts
301
304
  - St. Barths
305
+ - Saint Barthelemy
306
+ - Saint Barthélemy
307
+ - St. Barthélemy
302
308
  alpha2: BL
303
309
  alpha3: BLM
304
310
  fifa:
@@ -451,10 +457,15 @@ CC:
451
457
  shortcode: ":flag-cc:"
452
458
  CD:
453
459
  aliases:
460
+ - Congo Kinshasa
454
461
  - Congo-Kinshasa
455
- - DRC
456
- - DR Congo
457
462
  - Congo, The Democratic Republic Of The
463
+ - Congo, Democratic Republic of
464
+ - Democratic Republic of Congo
465
+ - DR Congo
466
+ - RD Congo
467
+ - DROC
468
+ - DRC
458
469
  alpha2: CD
459
470
  alpha3: COD
460
471
  fifa: COD
@@ -479,6 +490,7 @@ CF:
479
490
  CG:
480
491
  aliases:
481
492
  - Congo-Brazzaville
493
+ - Congo Brazzaville
482
494
  - Congo Republic
483
495
  - Congo, Republic of the
484
496
  alpha2: CG
@@ -503,6 +515,11 @@ CH:
503
515
  emoji: "\U0001F1E8\U0001F1ED"
504
516
  shortcode: ":flag-ch:"
505
517
  CI:
518
+ aliases:
519
+ - Côte D'Ivoire
520
+ - Côte D’Ivoire
521
+ - Cote D'Ivoire
522
+ - Cote D’Ivoire
506
523
  alpha2: CI
507
524
  alpha3: CIV
508
525
  fifa: CIV
@@ -536,6 +553,9 @@ CL:
536
553
  emoji: "\U0001F1E8\U0001F1F1"
537
554
  shortcode: ":flag-cl:"
538
555
  CM:
556
+ aliases:
557
+ - Cameroun
558
+ - Cameroon, Republic of
539
559
  alpha2: CM
540
560
  alpha3: CMR
541
561
  fifa: CMR
@@ -547,6 +567,8 @@ CM:
547
567
  emoji: "\U0001F1E8\U0001F1F2"
548
568
  shortcode: ":flag-cm:"
549
569
  CN:
570
+ aliases:
571
+ - PRC
550
572
  alpha2: CN
551
573
  alpha3: CHN
552
574
  fifa: CHN
@@ -837,6 +859,9 @@ FM:
837
859
  emoji: "\U0001F1EB\U0001F1F2"
838
860
  shortcode: ":flag-fm:"
839
861
  FO:
862
+ aliases:
863
+ - Faroes
864
+ - Faeroes
840
865
  alpha2: FO
841
866
  alpha3: FRO
842
867
  fifa: FRO
@@ -1050,6 +1075,9 @@ GU:
1050
1075
  emoji: "\U0001F1EC\U0001F1FA"
1051
1076
  shortcode: ":flag-gu:"
1052
1077
  GW:
1078
+ aliases:
1079
+ - Guinea Bissau
1080
+ - Republic of Guinea Bissau
1053
1081
  alpha2: GW
1054
1082
  alpha3: GNB
1055
1083
  fifa: GNB
@@ -2147,6 +2175,8 @@ QA:
2147
2175
  emoji: "\U0001F1F6\U0001F1E6"
2148
2176
  shortcode: ":flag-qa:"
2149
2177
  RE:
2178
+ aliases:
2179
+ - Reunion
2150
2180
  alpha2: RE
2151
2181
  alpha3: REU
2152
2182
  fifa:
@@ -2235,6 +2265,12 @@ SC:
2235
2265
  emoji: "\U0001F1F8\U0001F1E8"
2236
2266
  shortcode: ":flag-sc:"
2237
2267
  SD:
2268
+ aliases:
2269
+ - The Sudan
2270
+ - The Sudan, Republic of
2271
+ - Republic of Sudan
2272
+ - Sudan, Republic of
2273
+ - Sudan, Republic of the
2238
2274
  alpha2: SD
2239
2275
  alpha3: SDN
2240
2276
  fifa: SDN
@@ -2372,7 +2408,10 @@ SR:
2372
2408
  shortcode: ":flag-sr:"
2373
2409
  SS:
2374
2410
  aliases:
2411
+ - South Sudan, Republic of
2375
2412
  - S. Sudan
2413
+ - Republic of S. Sudan
2414
+ - S. Sudan, Republic of
2376
2415
  alpha2: SS
2377
2416
  alpha3: SSD
2378
2417
  fifa:
@@ -2387,6 +2426,11 @@ ST:
2387
2426
  aliases:
2388
2427
  - Democratic Republic of Sao Tome and Principe
2389
2428
  - São Tomé and Príncipe
2429
+ - Sao Tomé and Príncipe
2430
+ - Sao Tome and Príncipe
2431
+ - São Tomé and Principe
2432
+ - São Tome and Principe
2433
+ - São Tome and Príncipe
2390
2434
  alpha2: ST
2391
2435
  alpha3: STP
2392
2436
  fifa: STP
@@ -2456,7 +2500,7 @@ TC:
2456
2500
  iso_name: Turks and Caicos Islands
2457
2501
  numeric: "796"
2458
2502
  official: Turks and Caicos Islands
2459
- short: Turks and Caicos Islands
2503
+ short: Turks and Caicos
2460
2504
  emoji: "\U0001F1F9\U0001F1E8"
2461
2505
  shortcode: ":flag-tc:"
2462
2506
  TD:
@@ -3,7 +3,7 @@
3
3
  require "yaml"
4
4
 
5
5
  module NormalizeCountry
6
- VERSION = "0.3.1"
6
+ VERSION = "0.3.3"
7
7
  Countries = {}
8
8
 
9
9
  class << self
@@ -46,7 +46,7 @@ module NormalizeCountry
46
46
  end
47
47
  end
48
48
 
49
- class Country
49
+ class Country # :nodoc: all
50
50
  def initialize(config)
51
51
  raise ArgumentError, "country config must be a hash" unless Hash === config
52
52
 
@@ -78,7 +78,7 @@ module NormalizeCountry
78
78
  end
79
79
  end
80
80
 
81
- path = File.join(File.dirname(__FILE__), "normalize_country", "countries", "en.yml")
81
+ path = ENV["NORMALIZE_COUNTRY_DB"] || File.join(File.dirname(__FILE__), "normalize_country", "countries", "en.yml")
82
82
  data = YAML.load_file(path)
83
83
  data.values.each do |mapping|
84
84
  country = Country.new(mapping)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: normalize_country
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skye Shaw
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-01 00:00:00.000000000 Z
11
+ date: 2025-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -54,13 +54,12 @@ files:
54
54
  - bin/normalize_country
55
55
  - lib/normalize_country.rb
56
56
  - lib/normalize_country/countries/en.yml
57
- - lib/normalize_country/scanner.rb
58
57
  - spec/normalize_country_spec.rb
59
58
  homepage: http://github.com/sshaw/normalize_country
60
59
  licenses:
61
60
  - MIT
62
61
  metadata: {}
63
- post_install_message:
62
+ post_install_message:
64
63
  rdoc_options: []
65
64
  require_paths:
66
65
  - lib
@@ -75,9 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
74
  - !ruby/object:Gem::Version
76
75
  version: '0'
77
76
  requirements: []
78
- rubyforge_project:
79
- rubygems_version: 2.7.6
80
- signing_key:
77
+ rubygems_version: 3.5.16
78
+ signing_key:
81
79
  specification_version: 4
82
80
  summary: Convert country names and codes to a standard
83
81
  test_files:
@@ -1,121 +0,0 @@
1
- module NormalizeCountry
2
- class Tokenizer
3
- # Need numbers to match ISO codes
4
- # Need "-" to match emoji names
5
- # Need regex to match emojis
6
- PATTERN = /[[:word:]]+/
7
-
8
- def initialize(s)
9
- @scanner = StringScanner.new(s)
10
- end
11
-
12
- def scan
13
- @scanner.scan_until(PATTERN)
14
- @scanner.matched
15
- end
16
-
17
- def peek
18
- match = scan
19
- @scanner.unscan if match
20
- match
21
- end
22
-
23
- def end?
24
- peek.nil?
25
- end
26
- end
27
-
28
- class Scanner
29
- def initialize(options = nil)
30
- options ||= {}
31
-
32
- @to = options[:to] || NormalizeCountry.to
33
- @table = lookup_table(options[:from] || NormalizeCountry.formats) # need aliases!!!
34
- end
35
-
36
- def convert(text)
37
- s = Tokenizer.new(text)
38
-
39
- matches = []
40
- stack = []
41
- match_position = @table
42
-
43
- while !s.end?
44
- word = s.peek.downcase
45
- if !match_position[word]
46
- s.scan
47
- next
48
- end
49
-
50
- stack << s.scan
51
- alternatives = match_position[stack[-1].downcase]
52
-
53
- peek = s.peek
54
- if alternatives && peek && alternatives[peek.downcase]
55
- match_position = alternatives
56
- next
57
- end
58
-
59
- if match_position[stack[-1].downcase][:match]
60
- text = stack.join(" ")
61
- matches << { :matched => text, :converted => NormalizeCountry(text, :to => @to) }
62
-
63
- end
64
-
65
- stack.clear
66
- match_position = @table
67
- end
68
-
69
- matches
70
- end
71
-
72
- private
73
-
74
- def lookup_table(from_formats)
75
- table = {}
76
-
77
- NormalizeCountry::Countries.values.uniq.each_with_object(table) do |country, o|
78
- # country.name # eq all
79
- # no way to get aliases
80
- from_formats.each do |format|
81
- name = country[format]
82
- next unless name
83
-
84
- head = o
85
- parts = name.split(/[[:space:]]+/)
86
- parts.each_with_index do |word, i|
87
- # options[:case_sensitive_codes] = [x,y] # or true
88
- # options[:case_sensitive_formats] = [x,y]
89
- # options[:case_sensitive_formats] = true # alpha2, alpha3, fifa, ioc
90
- word.downcase! #unless parts.size == 1 && ABBRV_FORMATS.include?(format)
91
-
92
- # if head[word]
93
- # if i == parts.size - 1
94
- # head[word][:match] = true
95
- # else
96
- # head = head[word]
97
- # end
98
- # else
99
- # head[word] = {}
100
- # if i == parts.size - 1
101
- # head[word][:match] = true
102
- # else
103
- # head = head[word]
104
- # end
105
- # end
106
-
107
- head[word] = {} unless head[word]
108
-
109
- if i == parts.size - 1
110
- head[word][:match] = true
111
- else
112
- head = head[word]
113
- end
114
- end
115
- end
116
-
117
- o
118
- end
119
- end
120
- end
121
- end