city-state 0.1.0 → 0.1.1

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: 22dc3ee5f09c971103d3a93e13efacb3b61ed1fe02cb604a7f5eeef49a9205ee
4
- data.tar.gz: 6dc75d6663b0c8c3e0b59248e1de379c9c1598cfeaf5999795570d0b47e1b250
3
+ metadata.gz: 0dd92ab946196352480ea026ea14b427f321749dfabaabd347656577ffd4bbd8
4
+ data.tar.gz: 240d426e2b920fdedd2e478d5bf32ea227bb01b015ab3c9a23df34dd852c5199
5
5
  SHA512:
6
- metadata.gz: 82e920dcef289a72b7ef163e6cf7461438ffdca4907958dbbb5d5f6cd1b794f20a4482f1d49adef0d6c0b1ec88e2567faf7c4c3ca53395e603402600dedab1bf
7
- data.tar.gz: 2be31983767dabe77a888d351d1c84bb1db65d8c80a688f344677ba5c7ae116b645f11f382126742c5068b42cc8d9654095927dfea59005154fc7e31ad4d5417
6
+ metadata.gz: 28320ed1e61dd13379ff99456d1fe417ff2e54320c2ad5dbad4735bce01f6a2c19ef99013e2bfb973f1a5cd2b6831b81ebc7721ba5bf73ee3a28fcfb6a33deb7
7
+ data.tar.gz: 23679a1b7de164805ebbd9f09b7b2d8c6f9640dec5a43dae8c047752a357dd8a8b3cd0b1e8a74701a6f6c3ef71c753e43d73568c21d899ec1e09ad46b21ae5b2
data/CHANGELOG.md ADDED
@@ -0,0 +1,46 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.1] - 2023-08-19
9
+
10
+ ### Changed
11
+ - Updated `required_ruby_version` to restrict compatibility to Ruby 2.x. This version of the gem is now explicitly compatible only with Ruby 2. [@9f97d06](https://github.com/thecodecrate/city-state/commit/9f97d060c9774778497e624d05c45309fdaf5d68)
12
+
13
+ ### Notes
14
+ - Users running Ruby 3 or newer should refer to version `1.1.0` or later for compatibility.
15
+
16
+ ## [1.1.0] - 2023-08-14
17
+
18
+ ### Added
19
+ - Ruby 3 support.
20
+ - Development dependencies: `rspec 3.10`.
21
+ - Unit tests with RSpec.
22
+
23
+ ### Removed
24
+ - Ruby 2.5 support. Minimum Ruby version is now 2.6.0.
25
+ - `Gemfile.lock` from version control.
26
+
27
+ ### Changed
28
+ - Update bundled MaxMind database.
29
+ - Upgrade runtime dependencies: minimum Rake is 11.0, minimum Rubyzip is 2.3.
30
+
31
+ ## [0.1.0] - 2020-03-25
32
+
33
+ ### Added
34
+ - Methods `set_license_key(license_key)` and `set_maxmind_zip_url(url)`.
35
+
36
+ ### Removed
37
+ - Rails-specific code for broader Ruby compatibility.
38
+
39
+ ### Changed
40
+ - Improve methods for renaming and adding missing cities.
41
+ - Update bundled MaxMind database.
42
+ - Upgrade dependencies for security and compatibility.
43
+
44
+ ### Fixed
45
+ - Duplicated city entries. `CS.cities(:CA, :US)` multiple `Burbank` entries.
46
+ - Calling `CS.cities(nil)` returns random values.
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2020 Daniel Loureiro
1
+ Copyright (c) 2023 Daniel Loureiro
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,68 +1,76 @@
1
- # city-state ruby gem
1
+ # City-State Ruby Gem
2
2
 
3
- **city-state** is a very simple ruby gem to get a list of states in a country. Also, you can get a list of cities in a state, and a list of all countries of the world.
3
+ The `city-state` gem offers a straightforward way to retrieve lists of states for any given country and cities for any state. It's built on the MaxMind database, making it a reliable source for such data.
4
+
5
+ ## Installation
6
+
7
+ Add the gem to your Gemfile:
4
8
 
5
- ## Put this gem at your Gemfile:
6
9
  ```ruby
7
10
  gem 'city-state'
8
11
  ```
9
12
 
10
- ## List of states:
11
- ```ruby
12
- CS.states(:us)
13
- # => {:AK=>"Alaska", :AL=>"Alabama", :AR=>"Arkansas", :AZ=>"Arizona", :CA=>"California", :CO=>"Colorado", :CT=>"Connecticut", :DC=>"District of Columbia", :DE=>"Delaware", :FL=>"Florida", :GA=>"Georgia", :HI=>"Hawaii", :IA=>"Iowa", :ID=>"Idaho", :IL=>"Illinois", :IN=>"Indiana", :KS=>"Kansas", :KY=>"Kentucky", :LA=>"Louisiana", :MA=>"Massachusetts", :MD=>"Maryland", :ME=>"Maine", :MI=>"Michigan", :MN=>"Minnesota", :MO=>"Missouri", :MS=>"Mississippi", :MT=>"Montana", :NC=>"North Carolina", :ND=>"North Dakota", :NE=>"Nebraska", :NH=>"New Hampshire", :NJ=>"New Jersey", :NM=>"New Mexico", :NV=>"Nevada", :NY=>"New York", :OH=>"Ohio", :OK=>"Oklahoma", :OR=>"Oregon", :PA=>"Pennsylvania", :RI=>"Rhode Island", :SC=>"South Carolina", :SD=>"South Dakota", :TN=>"Tennessee", :TX=>"Texas", :UT=>"Utah", :VA=>"Virginia", :VT=>"Vermont", :WA=>"Washington", :WI=>"Wisconsin", :WV=>"West Virginia", :WY=>"Wyoming"}
14
- ```
15
- **PS:** *city-state is case insensitive. You can use :US, :us, :Us, "us", "US", ...*
13
+ Then, run:
16
14
 
17
- ## List of cities:
18
- ```ruby
19
- CS.cities(:ak, :us)
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"]
15
+ ```bash
16
+ $ bundle install
21
17
  ```
22
18
 
23
- ## All countries of the world:
19
+ ## Listing States:
20
+
21
+ Retrieve a list of states for a specified country:
22
+
24
23
  ```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"}
24
+ CS.states(:US)
27
25
  ```
26
+ **Note:** The gem is case-insensitive. You can use variations like `:US`, `:us`, `:Us`, `"us"`, and `"US"`.
28
27
 
29
- ## Simplified syntax with *get* method:
30
- * _CS.get_: list of countries (equivalent to `CS.countries`)
31
- * _CS.get(country)_: list of states (equivalent to `CS.states(country)`)
32
- * _CS.get(country, state)_: list of cities (equivalent to `CS.cities(state, country)`)
28
+ ## Listing Cities:
29
+
30
+ Retrieve a list of cities for a specified state and country:
33
31
 
34
- Example:
35
32
  ```ruby
36
- CS.get
37
- # => {: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"}
33
+ CS.cities(:AK, :US)
38
34
  ```
35
+
36
+ You can also specify the country, though it's optional. The gem remembers the last country you used:
37
+
39
38
  ```ruby
40
- CS.get :us
41
- # => {:AK=>"Alaska", :AL=>"Alabama", :AR=>"Arkansas", :AZ=>"Arizona", :CA=>"California", :CO=>"Colorado", :CT=>"Connecticut", :DC=>"District of Columbia", :DE=>"Delaware", :FL=>"Florida", :GA=>"Georgia", :HI=>"Hawaii", :IA=>"Iowa", :ID=>"Idaho", :IL=>"Illinois", :IN=>"Indiana", :KS=>"Kansas", :KY=>"Kentucky", :LA=>"Louisiana", :MA=>"Massachusetts", :MD=>"Maryland", :ME=>"Maine", :MI=>"Michigan", :MN=>"Minnesota", :MO=>"Missouri", :MS=>"Mississippi", :MT=>"Montana", :NC=>"North Carolina", :ND=>"North Dakota", :NE=>"Nebraska", :NH=>"New Hampshire", :NJ=>"New Jersey", :NM=>"New Mexico", :NV=>"Nevada", :NY=>"New York", :OH=>"Ohio", :OK=>"Oklahoma", :OR=>"Oregon", :PA=>"Pennsylvania", :RI=>"Rhode Island", :SC=>"South Carolina", :SD=>"South Dakota", :TN=>"Tennessee", :TX=>"Texas", :UT=>"Utah", :VA=>"Virginia", :VT=>"Vermont", :WA=>"Washington", :WI=>"Wisconsin", :WV=>"West Virginia", :WY=>"Wyoming"}
39
+ CS.states(:BR)
40
+
41
+ CS.cities(:TO) # This will use Brazil (BR) as the country
42
42
  ```
43
+
44
+ Miscellaneous Notes:
45
+ - The country is an optional argument. The gem always uses the last country that you used.
46
+
47
+ ## Listing Countries:
48
+
43
49
  ```ruby
44
- CS.get :us, :ak
45
- # => ["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"]
50
+ CS.countries
46
51
  ```
47
52
 
48
- # Missing cities and wrong names
53
+ ## Missing cities and wrong names
49
54
  To add missing cities or to rename wrong ones, create these files in your project folder:
50
55
  `db/cities-lookup.yml` and `db/states-lookup.yml` and `db/countries-lookup.yml`:
51
56
 
52
- 1) Renaming a country - `US` to `America`:
57
+ ### Renaming a country - `US` to `America`:
58
+
53
59
  ```yaml
54
60
  # db/countries-lookup.yml
55
61
  US: "America"
56
62
  ```
57
63
 
58
- 2) Renaming a state - `California` to `Something Else`:
64
+ ### Renaming a state - `California` to `Something Else`:
65
+
59
66
  ```yaml
60
67
  # db/states-lookup.yml
61
68
  US:
62
69
  CA: Something Else
63
70
  ```
64
71
 
65
- 3) Renaming a city:
72
+ ### Renaming a city:
73
+
66
74
  ```yaml
67
75
  # db/cities-lookup.yml
68
76
  US:
@@ -70,7 +78,8 @@ US:
70
78
  "Burbank": "Bur Bank"
71
79
  ```
72
80
 
73
- 4) Adding a missing city:
81
+ ### Adding a missing city:
82
+
74
83
  ```yaml
75
84
  # db/cities-lookup.yml
76
85
  US:
@@ -78,7 +87,7 @@ US:
78
87
  "My Town": "My Town"
79
88
  ```
80
89
 
81
- 5) Suppressing a city (set it as a blank line):
90
+ ### Suppressing a city (set it as a blank line):
82
91
  ```yaml
83
92
  # db/cities-lookup.yml
84
93
  US:
@@ -86,14 +95,17 @@ US:
86
95
  "Burbank": ""
87
96
  ```
88
97
 
89
- To use a different file instead of `db\cities-lookup.yml`:
98
+ ### To use a different file instead of `db\cities-lookup.yml`:
99
+
90
100
  ```ruby
91
101
  CS.set_cities_lookup_file('new-city-names.yml')
102
+
92
103
  CS.set_states_lookup_file('new-state-names.yml')
104
+
93
105
  CS.set_countries_lookup_file('new-country-names.yml')
94
106
  ```
95
107
 
96
- # Update the database from MaxMind
108
+ ## Updating MaxMind database
97
109
  MaxMind update their databases weekly on Tuesdays.
98
110
 
99
111
  Since Dec 30, 2019, MaxMind requires a license key (for free) to get download updates.
@@ -101,59 +113,46 @@ Since Dec 30, 2019, MaxMind requires a license key (for free) to get download up
101
113
  To get the license key:
102
114
  1. Sign up for a MaxMind account: https://www.maxmind.com/en/geolite2/signup
103
115
  2. Create a license key: https://www.maxmind.com/en/accounts/current/license-key
116
+ 3. There's no need to download anything.
104
117
 
105
118
  To update:
119
+
106
120
  ```ruby
107
121
  CS.set_license_key('MY_KEY')
122
+
108
123
  CS.update
109
124
  ```
110
- _*PS:* Replace "_MY_KEY_" with your actual key._
125
+ **Note:** Replace `MY_KEY` with your actual license key.
111
126
 
112
127
  ## Manually setting a database file:
128
+
113
129
  You can use an alternative database file instead of downloading from MaxMind servers:
130
+
114
131
  ```ruby
115
132
  CS.set_maxmind_zip_url('/home/daniel/GeoLite2-City-CSV_20200324.zip')
133
+
116
134
  CS.update
117
135
  ```
136
+
118
137
  or
138
+
119
139
  ```ruby
120
140
  CS.set_maxmind_zip_url('https://example.com/GeoLite2-City-CSV_20200324.zip')
141
+
121
142
  CS.update
122
143
  ```
123
144
 
124
- The file has to be a ZIP file. And it has contains a CVS file named `GeoLite2-City-Locations-en.csv`. This file must be in the MaxMind's GeoLite2 City's format.
145
+ The file has to be a ZIP file. And it has to contain a CVS file named `GeoLite2-City-Locations-en.csv`. This file must be in MaxMind's GeoLite2 City's format.
125
146
 
126
- # Other countries:
127
-
128
- When getting a city list, you can also specifies the country:
129
- ```ruby
130
- CS.cities(:sp, :br)
131
- ```
132
-
133
- The country is an optional argument. **city-state** always uses the last country that you used.
134
- ```ruby
135
- CS.states(:br)
136
- # => {:AC=>"Acre", :AL=>"Alagoas", :AM=>"Amazonas", :AP=>"Amapa", :BA=>"Bahia", :CE=>"Ceara", :DF=>"Federal District", :ES=>"Espirito Santo", :GO=>"Goias", :MA=>"Maranhao", :MG=>"Minas Gerais", :MS=>"Mato Grosso do Sul", :MT=>"Mato Grosso", :PA=>"Para", :PB=>"Paraiba", :PE=>"Pernambuco", :PI=>"Piaui", :PR=>"Parana", :RJ=>"Rio de Janeiro", :RN=>"Rio Grande do Norte", :RO=>"Rondonia", :RR=>"Roraima", :RS=>"Rio Grande do Sul", :SC=>"Santa Catarina", :SE=>"Sergipe", :SP=>"Sao Paulo", :TO=>"Tocantins"}
137
- CS.cities(:to)
138
- # => ["Aparecida do Rio Negro", "Araguaína", "Brejinho de Nazare", "Gurupi", "Itaguatins", "Miracema do Tocantins", "Monte Alegre", "Palmas", "Paraiso do Tocantins", "Parana", "Pedro Afonso", "Porto Nacional", "Presidente Kennedy", "Salvador", "Santo Antonio", "Sao Domingos", "Taguatinga", "Tucum"]
139
- ```
147
+ ## Changelog
148
+ See [CHANGELOG.md](CHANGELOG.md)
140
149
 
141
- # Changelog
142
- * 0.1.0:
143
- - [Minor] Added `set_license_key(license_key)` and `set_maxmind_zip_url(url)` methods;
144
- - [Minor] Removed Rails code, so it can be used on pure Ruby;
145
- - [Minor] Allow to rename and to add missing cities;
146
- - [Minor] Updated default MaxMind database;
147
- - [Fix] Filter duplicated elements (ex. `CS.cities(:ca, :us)` was returning `Burbank` twice);
148
- - [Fix] Upgraded dependencies (some had security issues);
149
- - [Fix] Calling `CS.cities(nil)` was returning random values;
150
-
151
- # More details about this gem
150
+ ## How this gem was created
152
151
  https://learnwithdaniel.com/2015/02/citystate-list-of-countries-cities-and-states-ruby/
153
152
 
154
- # CityState License
153
+ ## CityState License
155
154
  **city-state** is a open source project by Daniel Loureiro with a MIT license. Also, it uses MaxMind open source database.
156
155
 
157
- # MaxMind License
156
+ ## MaxMind License
158
157
  Database and Contents Copyright (c) 2020 MaxMind, Inc.
159
158
  This work is licensed under the Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/.
data/city-state.gemspec CHANGED
@@ -10,15 +10,22 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["loureirorg@gmail.com"]
11
11
  spec.summary = %q{Simple list of cities and states of the world}
12
12
  spec.description = %q{Useful to make forms and validations. It uses MaxMind database.}
13
- spec.homepage = "https://github.com/loureirorg/city-state"
13
+ spec.homepage = "https://github.com/thecodecrate/city-state"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.files = [
17
+ 'Rakefile',
18
+ 'README.md',
19
+ 'LICENSE.txt',
20
+ 'CHANGELOG.md',
21
+ 'city-state.gemspec'
22
+ ] + Dir["lib/**/*"] + Dir["spec/**/*"]
19
23
  spec.require_paths = ["lib"]
20
24
 
25
+ spec.required_ruby_version = '>= 2.0.0', '< 3.0.0'
26
+
21
27
  spec.add_development_dependency "bundler", ">= 1.7"
22
- spec.add_development_dependency "rake", ">= 10.0"
23
- spec.add_runtime_dependency "rubyzip", ">= 1.1"
28
+ spec.add_development_dependency "rake", ">= 11.0"
29
+ spec.add_runtime_dependency "rubyzip", ">= 2.3"
30
+ spec.add_development_dependency 'rspec', '~> 3.10'
24
31
  end
@@ -1,3 +1,3 @@
1
1
  module CS
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/city-state.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'uri'
1
2
  require "city-state/version"
2
3
  require 'yaml'
3
4
 
@@ -39,7 +40,7 @@ module CS
39
40
 
40
41
  # get zipped file
41
42
  return false if !@maxmind_zip_url
42
- f_zipped = open(@maxmind_zip_url)
43
+ f_zipped = URI.open(@maxmind_zip_url)
43
44
 
44
45
  # unzip file:
45
46
  # recursively searches for "GeoLite2-City-Locations-en"
@@ -75,7 +76,7 @@ module CS
75
76
 
76
77
  def self.install(country)
77
78
  # get CSV if doesn't exists
78
- update_maxmind unless File.exists? MAXMIND_DB_FN
79
+ update_maxmind unless File.exist? MAXMIND_DB_FN
79
80
 
80
81
  # normalize "country"
81
82
  country = country.to_s.upcase
@@ -163,7 +164,7 @@ module CS
163
164
  # load the country file
164
165
  if self.blank?(@cities[country])
165
166
  cities_fn = File.join(FILES_FOLDER, "cities.#{country.to_s.downcase}")
166
- self.install(country) if ! File.exists? cities_fn
167
+ self.install(country) if ! File.exist? cities_fn
167
168
  @cities[country] = self.symbolize_keys(YAML::load_file(cities_fn))
168
169
 
169
170
  # Remove duplicated cities
@@ -214,7 +215,7 @@ module CS
214
215
  if @cities_lookup.nil?
215
216
  @cities_lookup_fn = DEFAULT_CITIES_LOOKUP_FN if @cities_lookup_fn.nil?
216
217
  @cities_lookup_fn = File.expand_path(@cities_lookup_fn)
217
- return nil if ! File.exists?(@cities_lookup_fn)
218
+ return nil if ! File.exist?(@cities_lookup_fn)
218
219
  @cities_lookup = self.symbolize_keys(YAML::load_file(@cities_lookup_fn)) # force countries to be symbols
219
220
  @cities_lookup.each { |key, value| @cities_lookup[key] = self.symbolize_keys(value) } # force states to be symbols
220
221
  end
@@ -228,7 +229,7 @@ module CS
228
229
  if @states_lookup.nil?
229
230
  @states_lookup_fn = DEFAULT_STATES_LOOKUP_FN if @states_lookup_fn.nil?
230
231
  @states_lookup_fn = File.expand_path(@states_lookup_fn)
231
- return nil if ! File.exists?(@states_lookup_fn)
232
+ return nil if ! File.exist?(@states_lookup_fn)
232
233
  @states_lookup = self.symbolize_keys(YAML::load_file(@states_lookup_fn)) # force countries to be symbols
233
234
  @states_lookup.each { |key, value| @states_lookup[key] = self.symbolize_keys(value) } # force states to be symbols
234
235
  end
@@ -242,7 +243,7 @@ module CS
242
243
  if @countries_lookup.nil?
243
244
  @countries_lookup_fn = DEFAULT_COUNTRIES_LOOKUP_FN if @countries_lookup_fn.nil?
244
245
  @countries_lookup_fn = File.expand_path(@countries_lookup_fn)
245
- return nil if ! File.exists?(@countries_lookup_fn)
246
+ return nil if ! File.exist?(@countries_lookup_fn)
246
247
  @countries_lookup = self.symbolize_keys(YAML::load_file(@countries_lookup_fn)) # force countries to be symbols
247
248
  end
248
249
 
@@ -260,7 +261,7 @@ module CS
260
261
  # Load the country file
261
262
  if self.blank?(@states[country])
262
263
  states_fn = File.join(FILES_FOLDER, "states.#{country.to_s.downcase}")
263
- self.install(country) if ! File.exists? states_fn
264
+ self.install(country) if ! File.exist? states_fn
264
265
  @states[country] = self.symbolize_keys(YAML::load_file(states_fn))
265
266
 
266
267
  # Process lookup table
@@ -283,9 +284,9 @@ module CS
283
284
 
284
285
  # list of all countries of the world (countries.yml)
285
286
  def self.countries
286
- if ! File.exists? COUNTRIES_FN
287
+ if ! File.exist? COUNTRIES_FN
287
288
  # countries.yml doesn't exists, extract from MAXMIND_DB
288
- update_maxmind unless File.exists? MAXMIND_DB_FN
289
+ update_maxmind unless File.exist? MAXMIND_DB_FN
289
290
 
290
291
  # reads CSV line by line
291
292
  File.foreach(MAXMIND_DB_FN) do |line|