geo_states 0.1.0 → 0.1.2
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.
- checksums.yaml +4 -4
- data/geo_states-0.1.0.gem +0 -0
- data/lib/geo_states/version.rb +1 -1
- data/lib/geo_states.rb +24 -8
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 57ccab397c3c359acab87f1b0123fb5b8030bda122a6bbf80c211f945abc07e3
|
|
4
|
+
data.tar.gz: a16b689c9cd2a7105cf0606aca37690d719630ef1ca49298f2be66e4ebfd0fd4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2ad3fca95638be67289fc0c424e157c2be84456ff1a52f33b8e0e1c0d104bb98d57606e28b0be6a08c438cce7e7c860f385a5dd06adb4e4180a508a760747241
|
|
7
|
+
data.tar.gz: f0cca01a652a62ce867eeff381ac7053eea305796860cbe7115fbfbfcb5aa0b5446109034f492ff702f825f7bebf55919c112534aac921d42467ce63dd7ef9f4
|
|
Binary file
|
data/lib/geo_states/version.rb
CHANGED
data/lib/geo_states.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "geo_states/version"
|
|
4
|
+
require "geo_states/data_loader"
|
|
4
5
|
|
|
5
6
|
module GeoStates
|
|
6
7
|
class Error < StandardError; end
|
|
@@ -11,20 +12,37 @@ module GeoStates
|
|
|
11
12
|
DataLoader.countries
|
|
12
13
|
end
|
|
13
14
|
|
|
14
|
-
# Find country by
|
|
15
|
+
# Find country by any identifier (ISO2, ISO3, M49, or name).
|
|
16
|
+
# @param identifier [String] e.g. "MX", "MEX", "484", "Mexico"
|
|
17
|
+
# @return [Hash, nil]
|
|
18
|
+
def self.find_country(identifier)
|
|
19
|
+
find_country_by_iso2(identifier) ||
|
|
20
|
+
find_country_by_iso3(identifier) ||
|
|
21
|
+
find_country_by_m49(identifier) ||
|
|
22
|
+
find_country_by_name(identifier)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Find country by ISO 3166-1 alpha-2 code (e.g. "MX", "US").
|
|
15
26
|
# @param iso2 [String]
|
|
16
27
|
# @return [Hash, nil]
|
|
17
|
-
def self.
|
|
28
|
+
def self.find_country_by_iso2(iso2)
|
|
18
29
|
DataLoader.find_by_iso2(iso2)
|
|
19
30
|
end
|
|
20
31
|
|
|
21
|
-
# Find country by ISO 3166-1 alpha-3 (e.g. "MEX", "USA").
|
|
32
|
+
# Find country by ISO 3166-1 alpha-3 code (e.g. "MEX", "USA").
|
|
22
33
|
# @param iso3 [String]
|
|
23
34
|
# @return [Hash, nil]
|
|
24
35
|
def self.find_country_by_iso3(iso3)
|
|
25
36
|
DataLoader.find_by_iso3(iso3)
|
|
26
37
|
end
|
|
27
38
|
|
|
39
|
+
# Find country by UN M49 numeric code (e.g. "484", 484).
|
|
40
|
+
# @param m49 [String, Integer]
|
|
41
|
+
# @return [Hash, nil]
|
|
42
|
+
def self.find_country_by_m49(m49)
|
|
43
|
+
DataLoader.find_by_m49(m49)
|
|
44
|
+
end
|
|
45
|
+
|
|
28
46
|
# Find country by name (case-insensitive).
|
|
29
47
|
# @param name [String]
|
|
30
48
|
# @return [Hash, nil]
|
|
@@ -32,13 +50,11 @@ module GeoStates
|
|
|
32
50
|
DataLoader.find_by_name(name)
|
|
33
51
|
end
|
|
34
52
|
|
|
35
|
-
#
|
|
36
|
-
# @param identifier [String] ISO2, ISO3, or country name
|
|
53
|
+
# Return states (subdivisions) for a country. Accepts ISO2, ISO3, M49, or name.
|
|
54
|
+
# @param identifier [String] ISO2, ISO3, M49, or country name
|
|
37
55
|
# @return [Array<Hash>]
|
|
38
56
|
def self.states_for(identifier)
|
|
39
|
-
country = find_country(identifier)
|
|
40
|
-
find_country_by_iso3(identifier) ||
|
|
41
|
-
find_country_by_name(identifier)
|
|
57
|
+
country = find_country(identifier)
|
|
42
58
|
country&.dig(:states) || []
|
|
43
59
|
end
|
|
44
60
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: geo_states
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alberto Osnaya (@elosnaya)
|
|
@@ -21,6 +21,7 @@ files:
|
|
|
21
21
|
- LICENSE.txt
|
|
22
22
|
- README.md
|
|
23
23
|
- Rakefile
|
|
24
|
+
- geo_states-0.1.0.gem
|
|
24
25
|
- geo_states/data/countries.json
|
|
25
26
|
- lib/geo_states.rb
|
|
26
27
|
- lib/geo_states/data/countries.json
|