kountries 0.1.1

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.
@@ -0,0 +1,271 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kountries
4
+ # Oceania
5
+ module Oceania
6
+ def self.find_country_by_name(name)
7
+ constants.each do |country|
8
+ ocenia_country_class = Module.const_get "Kountries::Oceania::#{country}"
9
+ return as_struct(ocenia_country_class) if ocenia_country_class::NAME.upcase == name.upcase
10
+ return as_struct(ocenia_country_class) if ocenia_country_class::UN_OFFICIAL_NAMES.include?(name.capitalize)
11
+ end
12
+
13
+ empty_struct
14
+ end
15
+
16
+ def self.find_country_by_code(code)
17
+ return empty_struct unless Kountries::Oceania.constants.include?(code.intern)
18
+
19
+ ocenia_country_class = Module.const_get "Kountries::Oceania::#{code}"
20
+ return as_struct(ocenia_country_class) if ocenia_country_class::ALPHA_2 == code
21
+ end
22
+
23
+ def self.as_struct(oceania_country_class)
24
+ OpenStruct.new(
25
+ alpha2: oceania_country_class::ALPHA_2,
26
+ alpha3: oceania_country_class::ALPHA_3,
27
+ country_code: oceania_country_class::COUNTRY_CODE,
28
+ name: oceania_country_class::NAME,
29
+ unofficial_names: oceania_country_class::UN_OFFICIAL_NAMES
30
+ )
31
+ end
32
+
33
+ def self.empty_struct
34
+ OpenStruct.new(
35
+ alpha2: nil,
36
+ alpha3: nil,
37
+ country_code: nil,
38
+ name: nil,
39
+ unofficial_names: nil
40
+ )
41
+ end
42
+
43
+ class PG
44
+ ALPHA_2 = "PG"
45
+ ALPHA_3 = "PNG"
46
+ COUNTRY_CODE = "675"
47
+ NAME = "Papua New Guinea"
48
+ UN_OFFICIAL_NAMES = ["Papua New Guinea", "Papua-Neuguinea",
49
+ "Papouasie Nouvelle-Guinée", "Papúa Nueva Guinea",
50
+ "パプアニューギニア", "Papoea-Nieuw-Guinea"].freeze
51
+ end
52
+
53
+ class NU
54
+ ALPHA_2 = "NU"
55
+ ALPHA_3 = "NIU"
56
+ COUNTRY_CODE = "683"
57
+ NAME = "Niue"
58
+ UN_OFFICIAL_NAMES = %w[Niue ニウエ].freeze
59
+ end
60
+
61
+ class PF
62
+ ALPHA_2 = "PF"
63
+ ALPHA_3 = "PYF"
64
+ COUNTRY_CODE = "689"
65
+ NAME = "French Polynesia"
66
+ UN_OFFICIAL_NAMES = ["French Polynesia", "Französisch-Polynesien", "Polynésie Française",
67
+ "Polinesia Francesa", "フランス領ポリネシア", "Frans-Polynesië"].freeze
68
+ end
69
+
70
+ class TK
71
+ ALPHA_2 = "TK"
72
+ ALPHA_3 = "TKL"
73
+ COUNTRY_CODE = "690"
74
+ NAME = "Tokelau"
75
+ UN_OFFICIAL_NAMES = ["Tokelau", "Îles Tokelau", "Islas Tokelau", "トケラウ"].freeze
76
+ end
77
+
78
+ class NF
79
+ ALPHA_2 = "NF"
80
+ ALPHA_3 = "NFK"
81
+ COUNTRY_CODE = "672"
82
+ NAME = "Norfolk Island"
83
+ UN_OFFICIAL_NAMES = ["Norfolk Island", "Norfolkinsel", "Île de Norfolk", "Isla de Norfolk", "ノーフォーク島",
84
+ "Norfolkeiland"].freeze
85
+ end
86
+
87
+ class CC
88
+ ALPHA_2 = "CC"
89
+ ALPHA_3 = "CCK"
90
+ COUNTRY_CODE = "61"
91
+ NAME = "Cocos (Keeling) Islands"
92
+ UN_OFFICIAL_NAMES = ["Cocos (Keeling) Islands", "Kokosinseln", "ココス(キーリング)諸島", "Cocoseilanden"].freeze
93
+ end
94
+
95
+ class VU
96
+ ALPHA_2 = "VU"
97
+ ALPHA_3 = "VUT"
98
+ COUNTRY_CODE = "678"
99
+ NAME = "Vanuatu"
100
+ UN_OFFICIAL_NAMES = %w[Vanuatu バヌアツ].freeze
101
+ end
102
+
103
+ class WS
104
+ ALPHA_2 = "WS"
105
+ ALPHA_3 = "WSM"
106
+ COUNTRY_CODE = "685"
107
+ NAME = "Samoa"
108
+ UN_OFFICIAL_NAMES = %w[Samoa サモア].freeze
109
+ end
110
+
111
+ class WF
112
+ ALPHA_2 = "WF"
113
+ ALPHA_3 = "WLF"
114
+ COUNTRY_CODE = "681"
115
+ NAME = "Wallis and Futuna"
116
+ UN_OFFICIAL_NAMES = ["Wallis and Futuna", "Wallis und Futuna", "Wallis et Futuna", "Wallis y Futuna", "ウォリス・フツナ",
117
+ "Wallis en Futuna"].freeze
118
+ end
119
+
120
+ class NR
121
+ ALPHA_2 = "NR"
122
+ ALPHA_3 = "NRU"
123
+ COUNTRY_CODE = "674"
124
+ NAME = "Nauru"
125
+ UN_OFFICIAL_NAMES = %w[Nauru ナウル].freeze
126
+ end
127
+
128
+ class GU
129
+ ALPHA_2 = "GU"
130
+ ALPHA_3 = "GUM"
131
+ COUNTRY_CODE = "1"
132
+ NAME = "Guam"
133
+ UN_OFFICIAL_NAMES = %w[Guam グアム].freeze
134
+ end
135
+
136
+ class FJ
137
+ ALPHA_2 = "FJ"
138
+ ALPHA_3 = "FJI"
139
+ COUNTRY_CODE = "679"
140
+ NAME = "Fiji"
141
+ UN_OFFICIAL_NAMES = %w[Fiji Fidschi Fidji フィジー].freeze
142
+ end
143
+
144
+ class CX
145
+ ALPHA_2 = "CX"
146
+ ALPHA_3 = "CXR"
147
+ COUNTRY_CODE = "61"
148
+ NAME = "Christmas Island"
149
+ UN_OFFICIAL_NAMES = ["Christmas Island", "Weihnachtsinsel", "クリスマス島", "Christmaseiland"].freeze
150
+ end
151
+
152
+ class TO
153
+ ALPHA_2 = "TO"
154
+ ALPHA_3 = "TON"
155
+ COUNTRY_CODE = "676"
156
+ NAME = "Tonga"
157
+ UN_OFFICIAL_NAMES = %w[Tonga トンガ].freeze
158
+ end
159
+
160
+ class PN
161
+ ALPHA_2 = "PN"
162
+ ALPHA_3 = "PCN"
163
+ COUNTRY_CODE = "64"
164
+ NAME = "Pitcairn"
165
+ UN_OFFICIAL_NAMES = ["Pitcairn", "ピトケアン", "Pitcairneilanden", "Pitcairn Islands"].freeze
166
+ end
167
+
168
+ class AU
169
+ ALPHA_2 = "AU"
170
+ ALPHA_3 = "AUS"
171
+ COUNTRY_CODE = "61"
172
+ NAME = "Australia"
173
+ UN_OFFICIAL_NAMES = %w[Australia Australien Australie オーストラリア Australië].freeze
174
+ end
175
+
176
+ class PW
177
+ ALPHA_2 = "PW"
178
+ ALPHA_3 = "PLW"
179
+ COUNTRY_CODE = "680"
180
+ NAME = "Palau"
181
+ UN_OFFICIAL_NAMES = %w[Palau パラオ].freeze
182
+ end
183
+
184
+ class TV
185
+ ALPHA_2 = "TV"
186
+ ALPHA_3 = "TUV"
187
+ COUNTRY_CODE = "688"
188
+ NAME = "Tuvalu"
189
+ UN_OFFICIAL_NAMES = %w[Tuvalu ツバル].freeze
190
+ end
191
+
192
+ class CK
193
+ ALPHA_2 = "CK"
194
+ ALPHA_3 = "COK"
195
+ COUNTRY_CODE = "682"
196
+ NAME = "Cook Islands"
197
+ UN_OFFICIAL_NAMES = ["Cook Islands", "Cookinseln", "Îles Cook", "Islas Cook", "クック諸島", "Cookeilanden"].freeze
198
+ end
199
+
200
+ class KI
201
+ ALPHA_2 = "KI"
202
+ ALPHA_3 = "KIR"
203
+ COUNTRY_CODE = "686"
204
+ NAME = "Kiribati"
205
+ UN_OFFICIAL_NAMES = %w[Kiribati キリバス].freeze
206
+ end
207
+
208
+ class MH
209
+ ALPHA_2 = "MH"
210
+ ALPHA_3 = "MHL"
211
+ COUNTRY_CODE = "692"
212
+ NAME = "Marshall Islands"
213
+ UN_OFFICIAL_NAMES = ["Marshall Islands", "Marshallinseln", "Îles Marshall", "Islas Marshall", "マーシャル諸島",
214
+ "Marshalleilanden"].freeze
215
+ end
216
+
217
+ class NC
218
+ ALPHA_2 = "NC"
219
+ ALPHA_3 = "NCL"
220
+ COUNTRY_CODE = "687"
221
+ NAME = "New Caledonia"
222
+ UN_OFFICIAL_NAMES = ["New Caledonia", "Neukaledonien", "Nouvelle-Calédonie", "Nueva Caledonia", "ニューカレドニア",
223
+ "Nieuw-Caledonië"].freeze
224
+ end
225
+
226
+ class MP
227
+ ALPHA_2 = "MP"
228
+ ALPHA_3 = "MNP"
229
+ COUNTRY_CODE = "1"
230
+ NAME = "Northern Mariana Islands"
231
+ UN_OFFICIAL_NAMES = ["Northern Mariana Islands", "Nördliche Marianen", "Mariannes du Nord",
232
+ "Islas Marianas del Norte", "北マリアナ諸島",
233
+ "Noordelijke Marianeneilanden"].freeze
234
+ end
235
+
236
+ class NZ
237
+ ALPHA_2 = "NZ"
238
+ ALPHA_3 = "NZL"
239
+ COUNTRY_CODE = "64"
240
+ NAME = "New Zealand"
241
+ UN_OFFICIAL_NAMES = ["New Zealand", "Neuseeland", "Nouvelle Zélande", "Nueva Zelanda", "ニュージーランド",
242
+ "Nieuw-Zeeland"].freeze
243
+ end
244
+
245
+ class FM
246
+ ALPHA_2 = "FM"
247
+ ALPHA_3 = "FSM"
248
+ COUNTRY_CODE = "691"
249
+ NAME = "Micronesia (Federated States of)"
250
+ UN_OFFICIAL_NAMES = %w[Micronesia Mikronesien Micronésie ミクロネシア連邦 Micronesië].freeze
251
+ end
252
+
253
+ class SB
254
+ ALPHA_2 = "SB"
255
+ ALPHA_3 = "SLB"
256
+ COUNTRY_CODE = "677"
257
+ NAME = "Solomon Islands"
258
+ UN_OFFICIAL_NAMES = ["Solomon Islands", "Salomonen", "Îles Salomon", "Islas Salomón", "ソロモン諸島",
259
+ "Salomonseilanden"].freeze
260
+ end
261
+
262
+ class AS
263
+ ALPHA_2 = "AS"
264
+ ALPHA_3 = "ASM"
265
+ COUNTRY_CODE = "1"
266
+ NAME = "American Samoa"
267
+ UN_OFFICIAL_NAMES = ["American Samoa", "Amerikanisch-Samoa", "Samoa américaines", "Samoa Americana", "アメリカ領サモア",
268
+ "Amerikaans Samoa"].freeze
269
+ end
270
+ end
271
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kountries
4
+ VERSION = "0.1.1"
5
+ end
data/lib/kountries.rb ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "kountries/africa"
4
+ require_relative "kountries/america"
5
+ require_relative "kountries/asia"
6
+ require_relative "kountries/europe"
7
+ require_relative "kountries/lookup_by_code"
8
+ require_relative "kountries/lookup_by_name"
9
+ require_relative "kountries/oceania"
10
+ require_relative "kountries/version"
11
+
12
+ # Kountries gem
13
+ module Kountries
14
+ class Error < StandardError; end
15
+
16
+ def self.as_struct(country_class)
17
+ OpenStruct.new(
18
+ alpha2: country_class::ALPHA_2,
19
+ alpha3: country_class::ALPHA_3,
20
+ country_code: country_class::COUNTRY_CODE,
21
+ name: country_class::NAME,
22
+ unofficial_names: country_class::UN_OFFICIAL_NAMES
23
+ )
24
+ end
25
+
26
+ def self.empty_struct
27
+ OpenStruct.new(
28
+ alpha2: nil,
29
+ alpha3: nil,
30
+ country_code: nil,
31
+ name: nil,
32
+ unofficial_names: nil
33
+ )
34
+ end
35
+ end
data/sig/kountries.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Kountries
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kountries
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - sylvance_theone
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby gem that makes it easier to work with countries
14
+ email:
15
+ - 9350722+Sylvance@users.noreply.github.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - kountries.gemspec
29
+ - lib/kountries.rb
30
+ - lib/kountries/africa.rb
31
+ - lib/kountries/america.rb
32
+ - lib/kountries/asia.rb
33
+ - lib/kountries/europe.rb
34
+ - lib/kountries/lookup_by_code.rb
35
+ - lib/kountries/lookup_by_name.rb
36
+ - lib/kountries/oceania.rb
37
+ - lib/kountries/version.rb
38
+ - sig/kountries.rbs
39
+ homepage: https://github.com/Sylvance/kountries
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ allowed_push_host: https://rubygems.org
44
+ homepage_uri: https://github.com/Sylvance/kountries
45
+ source_code_uri: https://github.com/Sylvance/kountries
46
+ changelog_uri: https://github.com/Sylvance/kountries/CHANGELOG.md
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.6.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.2.22
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Ruby gem that makes it easier to work with countries
66
+ test_files: []