urbans 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 57eecd5a9008ba71174850132c0c74201712080b
4
+ data.tar.gz: 5aa6927d7f4d3036943c0f09d99dc5e3ec819272
5
+ SHA512:
6
+ metadata.gz: edcd375d05258138320e19e671b94cb6a230871a350ba3c76fead36363558832e3a9adf5c54734c3d844e8a992efec3ccf85a52f77c7895d64857e96338e3f34
7
+ data.tar.gz: 6711cb890d302219f6b37bac138bbff4110d9557a1d42f5e511eb40edd033f16462e33b7a1e087e51419c03f10b6ecfd4ace8feb416e833b424e02c48de584d7
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.swp
12
+ *.swo
13
+ *.gem
14
+ *.gemspec
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in urbanss.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Adam Pahlevi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # Urbans
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/urbanss`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'urbans'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install urbanss
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/urbanss. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "urbans"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,73 @@
1
+ require "urbans/version"
2
+
3
+ require "yaml"
4
+
5
+ # exceptions
6
+ require "urbans/exceptions/urban_error"
7
+
8
+ # foundations
9
+ require "urbans/foundations/city"
10
+ require "urbans/foundations/country"
11
+ require "urbans/foundations/province"
12
+
13
+ require "urbans/configurer"
14
+
15
+ module Urbans
16
+ URBAN_PATH = File.expand_path(File.dirname(__FILE__)) + "/"
17
+
18
+ # all avalable countries supported by Urbans
19
+ ALL_COUNTRIES = [:id]
20
+
21
+ # all available locales
22
+ ALL_LOCALES = [:id, :en]
23
+ @@default_locale = nil
24
+
25
+ # mapping of countries and locales, eg:
26
+ # {
27
+ # id: {en: Indonesia, id: Indonesia}
28
+ # }
29
+ # only load locale when necessary
30
+ COUNTRIES = {}
31
+
32
+ # mapping of provinces and locales, eg:
33
+ # {
34
+ # id_pv_ach: {en: "Aceh", id: "Aceh"}
35
+ # }
36
+ # only load locale when necessary
37
+ PROVINCES = {}
38
+
39
+ # similar to above
40
+ CITIES = {}
41
+
42
+ module_function
43
+
44
+ def config(&block)
45
+ Urbans::Configurer.new.instance_eval(&block)
46
+ end
47
+
48
+ def locale=(locale)
49
+ if ALL_LOCALES.include?(locale.to_sym)
50
+ @@default_locale = locale.to_sym
51
+ else
52
+ raise Urbans::Error, "Unsupported locale: #{locale}."
53
+ end
54
+ end
55
+
56
+ def locale
57
+ raise Urbans::Error, "Locale have not been set yet" if @@default_locale.nil?
58
+ @@default_locale
59
+ end
60
+
61
+ def country
62
+ Urbans::Country
63
+ end
64
+
65
+ def province
66
+ Urbans::Province
67
+ end
68
+
69
+ def city
70
+ Urbans::City
71
+ end
72
+
73
+ end
@@ -0,0 +1,30 @@
1
+ class Urbans::Configurer
2
+ # explicitly load countries
3
+ def load_countries *args
4
+ countries = []
5
+ options = {}
6
+ args.each do |arg|
7
+ if arg.is_a?(String) || arg.is_a?(Symbol)
8
+ countries << arg
9
+ else
10
+ options = arg
11
+ end
12
+ end
13
+
14
+ original_locale = Urbans.locale
15
+ locales = options[:locale] || Urbans.locale
16
+ locales = [locales] unless locales.is_a?(Array)
17
+
18
+ locales.each do |locale|
19
+ Urbans.locale = locale
20
+ # preload!
21
+ countries.each do |country_name|
22
+ country = Urbans.country.get country_name
23
+ country.provinces
24
+ country.provinces.first.cities
25
+ end
26
+ end
27
+
28
+ Urbans.locale = original_locale
29
+ end
30
+ end
@@ -0,0 +1,494 @@
1
+ en:
2
+ countries:
3
+ "AF":
4
+ name: "Afghanistan"
5
+ "ZA":
6
+ name: "South Africa"
7
+ "CF":
8
+ name: "Central African Republic"
9
+ "AX":
10
+ name: "Åland Islands"
11
+ "AL":
12
+ name: "Albania"
13
+ "DZ":
14
+ name: "Algeria"
15
+ "US":
16
+ name: "United States"
17
+ "AD":
18
+ name: "Andorra"
19
+ "AO":
20
+ name: "Angola"
21
+ "AI":
22
+ name: "Anguilla"
23
+ "AQ":
24
+ name: "Antarctica"
25
+ "AG":
26
+ name: "Antigua and Barbuda"
27
+ "AN":
28
+ name: "Netherlands Antilles"
29
+ "SA":
30
+ name: "Saudi Arabia"
31
+ "AR":
32
+ name: "Argentina"
33
+ "AM":
34
+ name: "Armenia"
35
+ "AW":
36
+ name: "Aruba"
37
+ "AU":
38
+ name: "Australia"
39
+ "AT":
40
+ name: "Austria"
41
+ "AZ":
42
+ name: "Azerbaijan"
43
+ "BS":
44
+ name: "Bahamas"
45
+ "BH":
46
+ name: "Bahrain"
47
+ "BD":
48
+ name: "Bangladesh"
49
+ "BB":
50
+ name: "Barbados"
51
+ "NL":
52
+ name: "Netherlands"
53
+ "BY":
54
+ name: "Belarus"
55
+ "BE":
56
+ name: "Belgium"
57
+ "BZ":
58
+ name: "Belize"
59
+ "BJ":
60
+ name: "Benin"
61
+ "BM":
62
+ name: "Bermuda"
63
+ "BT":
64
+ name: "Bhutan"
65
+ "BO":
66
+ name: "Bolivia"
67
+ "BA":
68
+ name: "Bosnia and Herzegovina"
69
+ "BW":
70
+ name: "Bostwana"
71
+ "BV":
72
+ name: "Bouvet Island"
73
+ "BR":
74
+ name: "Brazil"
75
+ "GB":
76
+ name: "United Kingdom"
77
+ "BN":
78
+ name: "Brunei Darussalam"
79
+ "BG":
80
+ name: "Bulgaria"
81
+ "BF":
82
+ name: "Burkina Faso"
83
+ "BI":
84
+ name: "Burundi"
85
+ "KY":
86
+ name: "Cayman Islands"
87
+ "TD":
88
+ name: "Chad"
89
+ "CZ":
90
+ name: "Czech Republic"
91
+ "CL":
92
+ name: "Chile"
93
+ "CC":
94
+ name: "Cocos (Keeling) Islands"
95
+ "CK":
96
+ name: "Cook Islands"
97
+ "DK":
98
+ name: "Denmark"
99
+ "DJ":
100
+ name: "Djibouti"
101
+ "DM":
102
+ name: "Dominica"
103
+ "DO":
104
+ name: "Dominican Republic"
105
+ "EC":
106
+ name: "Ecuador"
107
+ "SV":
108
+ name: "El Salvador"
109
+ "ER":
110
+ name: "Eritrea"
111
+ "EE":
112
+ name: "Estonia"
113
+ "ET":
114
+ name: "Ethiopia"
115
+ "FK":
116
+ name: "Falkland Islands"
117
+ "FO":
118
+ name: "Faroe Islands"
119
+ "FJ":
120
+ name: "Fiji"
121
+ "PH":
122
+ name: "Philippines"
123
+ "FI":
124
+ name: "Finland"
125
+ "GA":
126
+ name: "Gabon"
127
+ "GM":
128
+ name: "Gambia"
129
+ "GE":
130
+ name: "Georgia"
131
+ "GS":
132
+ name: "South Georgia and the South Sandwich Islands"
133
+ "GH":
134
+ name: "Ghana"
135
+ "GI":
136
+ name: "Gibraltar"
137
+ "GL":
138
+ name: "Greenland"
139
+ "GD":
140
+ name: "Grenada"
141
+ "GP":
142
+ name: "Guadeloupe"
143
+ "GU":
144
+ name: "Guam"
145
+ "GT":
146
+ name: "Guatemala"
147
+ "GG":
148
+ name: "Guernsey"
149
+ "GN":
150
+ name: "Guinea"
151
+ "GW":
152
+ name: "Guinea-Bissau"
153
+ "GQ":
154
+ name: "Equatorial Guinea"
155
+ "GY":
156
+ name: "Guyana"
157
+ "GF":
158
+ name: "French Guiana"
159
+ "HT":
160
+ name: "Haiti"
161
+ "HM":
162
+ name: "Heard Island and McDonald Islands"
163
+ "HN":
164
+ name: "Honduras"
165
+ "HK":
166
+ name: "Hong Kong"
167
+ "HU":
168
+ name: "Hungary"
169
+ "IS":
170
+ name: "Iceland"
171
+ "IN":
172
+ name: "India"
173
+ "ID":
174
+ name: "Indonesia"
175
+ "IQ":
176
+ name: "Iraq"
177
+ "IR":
178
+ name: "Iran, Islamic Republic of"
179
+ "IE":
180
+ name: "Republic of Ireland"
181
+ "IL":
182
+ name: "Israel"
183
+ "IT":
184
+ name: "Italy"
185
+ "JM":
186
+ name: "Jamaica"
187
+ "JP":
188
+ name: "Japan"
189
+ "DE":
190
+ name: "Germany"
191
+ "JE":
192
+ name: "Jersey"
193
+ "NC":
194
+ name: "New Caledonia"
195
+ "KH":
196
+ name: "Cambodia"
197
+ "CM":
198
+ name: "Cameroon"
199
+ "CA":
200
+ name: "Canada"
201
+ "KZ":
202
+ name: "Kazakhstan"
203
+ "KE":
204
+ name: "Kenya"
205
+ "KI":
206
+ name: "Kiribati"
207
+ "KG":
208
+ name: "Kyrgyzstan"
209
+ "CO":
210
+ name: "Colombia"
211
+ "KM":
212
+ name: "Comoros"
213
+ "CG":
214
+ name: "Republic of the Congo"
215
+ "CD":
216
+ name: "Democratic Republic of the Congo"
217
+ "KR":
218
+ name: "Korea, Republic of"
219
+ "KP":
220
+ name: "Korea, Demokratic People's Republic of"
221
+ "CR":
222
+ name: "Costa Rica"
223
+ "HR":
224
+ name: "Croatia"
225
+ "CU":
226
+ name: "Cuba"
227
+ "KW":
228
+ name: "Kuwait"
229
+ "LA":
230
+ name: "Lao People's Democratic Republic"
231
+ "LV":
232
+ name: "Latvia"
233
+ "LB":
234
+ name: "Lebanon"
235
+ "LS":
236
+ name: "Lesotho"
237
+ "LR":
238
+ name: "Liberia"
239
+ "LY":
240
+ name: "Libyan Arab Jamahiriya"
241
+ "LI":
242
+ name: "Liechtenstein"
243
+ "LT":
244
+ name: "Lithuania"
245
+ "LU":
246
+ name: "Luxembourg"
247
+ "MO":
248
+ name: "Macao"
249
+ "MK":
250
+ name: "Republic of Macedonia"
251
+ "MG":
252
+ name: "Madagascar"
253
+ "MW":
254
+ name: "Malawi"
255
+ "MY":
256
+ name: "Malaysia"
257
+ "MV":
258
+ name: "Maldives"
259
+ "ML":
260
+ name: "Mali"
261
+ "MT":
262
+ name: "Malta"
263
+ "IM":
264
+ name: "Isle of Man"
265
+ "MP":
266
+ name: "Northern Mariana Islands"
267
+ "MA":
268
+ name: "Marocco"
269
+ "MH":
270
+ name: "Marshall Islands"
271
+ "MQ":
272
+ name: "Martinique"
273
+ "MR":
274
+ name: "Mauritania"
275
+ "MU":
276
+ name: "Mauritius"
277
+ "YT":
278
+ name: "Mayotte"
279
+ "MX":
280
+ name: "Mexico"
281
+ "FM":
282
+ name: "Federates States of Micronesia"
283
+ "MD":
284
+ name: "Moldova"
285
+ "EG":
286
+ name: "Egypt"
287
+ "MC":
288
+ name: "Monaco"
289
+ "UM":
290
+ name: "United States Minor Outlying Islands"
291
+ "MN":
292
+ name: "Mongolia"
293
+ "ME":
294
+ name: "Montenegro"
295
+ "MS":
296
+ name: "Montserrat"
297
+ "MZ":
298
+ name: "Mozambique"
299
+ "MM":
300
+ name: "Myanmar"
301
+ "NA":
302
+ name: "Namibia"
303
+ "NR":
304
+ name: "Nauru"
305
+ "CX":
306
+ name: "Christmas Island"
307
+ "NP":
308
+ name: "Nepal"
309
+ "NI":
310
+ name: "Nicaragua"
311
+ "NE":
312
+ name: "Niger"
313
+ "NG":
314
+ name: "Nigeria"
315
+ "NU":
316
+ name: "Niue"
317
+ "NF":
318
+ name: "Norfolk Island"
319
+ "NO":
320
+ name: "Norway"
321
+ "OM":
322
+ name: "Oman"
323
+ "PK":
324
+ name: "Pakistan"
325
+ "PW":
326
+ name: "Palau"
327
+ "PS":
328
+ name: "Palestinian Territory, Occupied"
329
+ "PA":
330
+ name: "Panama"
331
+ "CI":
332
+ name: "Côte d'Ivoire"
333
+ "PG":
334
+ name: "Papua New Guinea"
335
+ "PY":
336
+ name: "Paraguay"
337
+ "FR":
338
+ name: "France"
339
+ "TF":
340
+ name: "French Southern Territories"
341
+ "PE":
342
+ name: "Peru"
343
+ "PN":
344
+ name: "Pitcairn"
345
+ "PL":
346
+ name: "Poland"
347
+ "PF":
348
+ name: "French Polynesia"
349
+ "PT":
350
+ name: "Portugal"
351
+ "PR":
352
+ name: "Puerto Rico"
353
+ "QA":
354
+ name: "Qatar"
355
+ "RE":
356
+ name: "Réunion"
357
+ "RO":
358
+ name: "Romania"
359
+ "RU":
360
+ name: "Russian Federation"
361
+ "RW":
362
+ name: "Rwanda"
363
+ "EH":
364
+ name: "Western Sahara"
365
+ "BL":
366
+ name: "Saint Barthélemy"
367
+ "SH":
368
+ name: "Saint Helena, Ascension and Tristan da Cunha"
369
+ "KN":
370
+ name: "Saint Kitts and Nevis"
371
+ "LC":
372
+ name: "Saint Lucia"
373
+ "MF":
374
+ name: "Saint Martin (French part)"
375
+ "PM":
376
+ name: "Saint-Pierre and Miquelon"
377
+ "VC":
378
+ name: "Saint Vincent and the Grenadines"
379
+ "WS":
380
+ name: "Samoa"
381
+ "AS":
382
+ name: "American Samoa"
383
+ "IO":
384
+ name: "British Indian Ocean Territory"
385
+ "SM":
386
+ name: "San Marino"
387
+ "ST":
388
+ name: "São Tomé and Príncipe"
389
+ "NZ":
390
+ name: "New Zealand"
391
+ "SN":
392
+ name: "Senegal"
393
+ "RS":
394
+ name: "Serbia"
395
+ "SC":
396
+ name: "Seychelles"
397
+ "SL":
398
+ name: "Sierra Leone"
399
+ "SG":
400
+ name: "Singapore"
401
+ "CY":
402
+ name: "Cyprus"
403
+ "SI":
404
+ name: "Slovenia"
405
+ "SK":
406
+ name: "Slovakia"
407
+ "SB":
408
+ name: "Salomon Islands"
409
+ "SO":
410
+ name: "Somalia"
411
+ "ES":
412
+ name: "Spain"
413
+ "LK":
414
+ name: "Sri Lanka"
415
+ "SD":
416
+ name: "Sudan"
417
+ "SY":
418
+ name: "Syrian Arab Republic"
419
+ "SR":
420
+ name: "Suriname"
421
+ "SJ":
422
+ name: "Svalbard and Jan Mayen"
423
+ "SZ":
424
+ name: "Swaziland"
425
+ "SE":
426
+ name: "Sweden"
427
+ "CH":
428
+ name: "Switzerland"
429
+ "TW":
430
+ name: "Republic of China (Taiwan)"
431
+ "TJ":
432
+ name: "Tajikistan"
433
+ "CV":
434
+ name: "Cape Verde"
435
+ "TZ":
436
+ name: "Tanzania"
437
+ "TH":
438
+ name: "Thailand"
439
+ "TL":
440
+ name: "Timor Leste"
441
+ "CN":
442
+ name: "People's Republic of China"
443
+ "TG":
444
+ name: "Togo"
445
+ "TK":
446
+ name: "Tokelau"
447
+ "TO":
448
+ name: "Tonga"
449
+ "TT":
450
+ name: "Trinidad and Tobago"
451
+ "TN":
452
+ name: "Tunisia"
453
+ "TR":
454
+ name: "Turkey"
455
+ "TM":
456
+ name: "Turkmenistan"
457
+ "TC":
458
+ name: "Turks and Caicos Islands"
459
+ "TV":
460
+ name: "Tuvalu"
461
+ "UG":
462
+ name: "Uganda"
463
+ "UA":
464
+ name: "Ukraine"
465
+ "AE":
466
+ name: "United Arab Emirates"
467
+ "UY":
468
+ name: "Uruguay"
469
+ "UZ":
470
+ name: "Uzbekistan"
471
+ "VU":
472
+ name: "Vanuatu"
473
+ "VA":
474
+ name: "Vatican City"
475
+ "VE":
476
+ name: "Venezuela"
477
+ "VN":
478
+ name: "Viet Nam"
479
+ "VI":
480
+ name: "U.S. Virgin Islands"
481
+ "VG":
482
+ name: "British Virgin Islands"
483
+ "WF":
484
+ name: "Wallis and Futuna"
485
+ "YE":
486
+ name: "Yemen"
487
+ "JO":
488
+ name: "Jordan"
489
+ "GR":
490
+ name: "Greece"
491
+ "ZM":
492
+ name: "Zambia"
493
+ "ZW":
494
+ name: "Zimbabwe"