city-state 0.0.9.6 → 0.0.10

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: ab62516b059dbebf162e8c890338147da4e96cba
4
- data.tar.gz: fbe03dc8cd47eaeecaaae204a5afb2bfb90c3f2f
3
+ metadata.gz: dfe91c13079d671f4da2fcd328c848c3dd20ab49
4
+ data.tar.gz: 0f541c9110cc637fa777f73cd29c5015cc0cf223
5
5
  SHA512:
6
- metadata.gz: 20f2e155d5fcb949995ab5f71507ca302f073a065f5aacf24f430ef7c3f395aa2beb102beb9dcbcb60257818b2f1cbbf83de4797774d5b2fbe1984c768467c95
7
- data.tar.gz: 06738a97ec3f12c0b04b17e887f5e498baa5dbe854accb105eea15709ae86f084ddcf242c5c8575009b1a2d596ef42ed44e417226698d668e654ea6b35ce0296
6
+ metadata.gz: 4543724c8dc5699064f98073307c643e214851bb74694102b3422567e115a3edfc7c3d3c6c5d208abb4f6a57fcbad669fc9ddabd0d010b63bd63c334f46af560
7
+ data.tar.gz: 708a0a204e8236fdd5a048b1c1f924900f8ca8802b94075ef952c0e60957a696cead803c68ea2c687f4a350e60079585af07bb695049e252bb4c0d2cbebc56ae
data/README.md CHANGED
@@ -20,6 +20,12 @@ CS.cities(:ak, :us)
20
20
  # => ["Adak", "Akhiok", "Akiachak", "Akiak", "Akutan", "Alakanuk", "Ambler", "Anchor Point", "Anchorage", "Angoon", "Atqasuk", "Barrow", "Bell Island Hot Springs", "Bethel", "Big Lake", "Buckland", "Chefornak", "Chevak", "Chicken", "Chugiak", "Coffman Cove", "Cooper Landing", "Copper Center", "Cordova", "Craig", "Deltana", "Dillingham", "Douglas", "Dutch Harbor", "Eagle River", "Eielson Air Force Base", "Fairbanks", "Fairbanks North Star Borough", "Fort Greely", "Fort Richardson", "Galena", "Girdwood", "Goodnews Bay", "Haines", "Homer", "Hooper Bay", "Juneau", "Kake", "Kaktovik", "Kalskag", "Kenai", "Ketchikan", "Kiana", "King Cove", "King Salmon", "Kipnuk", "Klawock", "Kodiak", "Kongiganak", "Kotlik", "Koyuk", "Kwethluk", "Levelock", "Manokotak", "May Creek", "Mekoryuk", "Metlakatla", "Mountain Village", "Nabesna", "Naknek", "Nazan Village", "Nenana", "New Stuyahok", "Nikiski", "Ninilchik", "Noatak", "Nome", "Nondalton", "Noorvik", "North Pole", "Northway", "Old Kotzebue", "Palmer", "Pedro Bay", "Petersburg", "Pilot Station", "Point Hope", "Point Lay", "Prudhoe Bay", "Russian Mission", "Sand Point", "Scammon Bay", "Selawik", "Seward", "Shungnak", "Sitka", "Skaguay", "Soldotna", "Stebbins", "Sterling", "Sutton", "Talkeetna", "Teller", "Thorne Bay", "Togiak", "Tok", "Toksook Bay", "Tuntutuliak", "Two Rivers", "Unalakleet", "Unalaska", "Valdez", "Wainwright", "Wasilla"]
21
21
  ```
22
22
 
23
+ ## Get a list of all countries of the world:
24
+ ```ruby
25
+ CS.countries
26
+ # => {:AD=>"Andorra", :AE=>"United Arab Emirates", :AF=>"Afghanistan", :AG=>"Antigua and Barbuda", :AI=>"Anguilla", :AL=>"Albania", :AM=>"Armenia", :AO=>"Angola", :AQ=>"Antarctica", :AR=>"Argentina", :AS=>"American Samoa", :AT=>"Austria", :AU=>"Australia", :AW=>"Aruba", :AX=>"Åland", :AZ=>"Azerbaijan", :BA=>"Bosnia and Herzegovina", :BB=>"Barbados", :BD=>"Bangladesh", :BE=>"Belgium", :BF=>"Burkina Faso", :BG=>"Bulgaria", :BH=>"Bahrain", :BI=>"Burundi", :BJ=>"Benin", :BL=>"Saint-Barthélemy", :BM=>"Bermuda", :BN=>"Brunei", :BO=>"Bolivia", :BQ=>"Bonaire", :BR=>"Brazil", :BS=>"Bahamas", :BT=>"Bhutan", :BW=>"Botswana", :BY=>"Belarus", :BZ=>"Belize", :CA=>"Canada", :CC=>"Cocos [Keeling] Islands", :CD=>"Congo", :CF=>"Central African Republic", :CG=>"Republic of the Congo"}
27
+ ```
28
+
23
29
  ## Update the database from MaxMind:
24
30
  MaxMind update their databases weekly on tuesdays. To get a new and updated version, you can update with:
25
31
  ```ruby
@@ -7,7 +7,7 @@ module CS
7
7
  MAXMIND_DB_FN = File.join(FILES_FOLDER, "GeoLite2-City-Locations-en.csv")
8
8
  COUNTRIES_FN = File.join(FILES_FOLDER, "countries.yml")
9
9
 
10
- @countries = @states = @cities = {}
10
+ @countries, @states, @cities = [{}, {}, {}]
11
11
  @current_country = nil # :US, :BR, :GB, :JP, ...
12
12
 
13
13
  def self.update_maxmind
@@ -56,13 +56,26 @@ module CS
56
56
  # normalize "country"
57
57
  country = country.to_s.upcase
58
58
 
59
+ # some state codes are empty: we'll use "states-replace" in these cases
60
+ states_replace_fn = File.join(FILES_FOLDER, "states-replace.yml")
61
+ states_replace = YAML::load_file(states_replace_fn).symbolize_keys
62
+ states_replace = states_replace[country.to_sym] || {} # we need just this country
63
+ states_replace_inv = states_replace.invert # invert key with value, to ease the search
64
+
59
65
  # read CSV line by line
60
66
  cities = {}
61
67
  states = {}
62
68
  File.foreach(MAXMIND_DB_FN) do |line|
63
69
  rec = line.split(",")
64
70
  next if rec[COUNTRY] != country
65
- next if rec[STATE].blank? || rec[CITY].blank?
71
+ next if (rec[STATE].blank? && rec[STATE_LONG].blank?) || rec[CITY].blank?
72
+
73
+ # some state codes are empty: we'll use "states-replace" in these cases
74
+ rec[STATE] = states_replace_inv[rec[STATE_LONG]] if rec[STATE].blank?
75
+ rec[STATE] = rec[STATE_LONG] if rec[STATE].blank? # there's no correspondent in states-replace: we'll use the long name as code
76
+
77
+ # some long names are empty: we'll use "states-replace" to get the code
78
+ rec[STATE_LONG] = states_replace[rec[STATE]] if rec[STATE_LONG].blank?
66
79
 
67
80
  # normalize
68
81
  rec[STATE] = rec[STATE].to_sym
@@ -96,7 +109,7 @@ module CS
96
109
  def self.current_country
97
110
  return @current_country if @current_country.present?
98
111
 
99
- # we don't have used this module yet: discover by the file extension
112
+ # we don't have used this method yet: discover by the file extension
100
113
  fn = Dir[File.join(FILES_FOLDER, "cities.*")].last
101
114
  @current_country = fn.blank? ? nil : fn.split(".").last
102
115
 
@@ -142,7 +155,7 @@ module CS
142
155
  @states[country] = YAML::load_file(states_fn).symbolize_keys
143
156
  end
144
157
 
145
- @states[country] || []
158
+ @states[country] || {}
146
159
  end
147
160
 
148
161
  # list of all countries of the world (countries.yml)
@@ -1,3 +1,3 @@
1
1
  module CS
2
- VERSION = "0.0.9.6"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -0,0 +1,3 @@
1
+ ---
2
+ :IN:
3
+ :TG: Telangana
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: city-state
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9.6
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Loureiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2015-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,6 +68,7 @@ files:
68
68
  - lib/city-state.rb
69
69
  - lib/city-state/version.rb
70
70
  - lib/db/GeoLite2-City-Locations-en.csv
71
+ - lib/db/states-replace.yml
71
72
  homepage: https://github.com/loureirorg/city-state
72
73
  licenses:
73
74
  - MIT