geo_states 0.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a0c6519178af969c2358e5ba7402bdec603bf7cd7dc69dd1afc4b43b4b20d48
4
- data.tar.gz: 0676e02cd3f7d22b384b6a02b4175122e05029ca04b6e7262c085e4da123611e
3
+ metadata.gz: 57ccab397c3c359acab87f1b0123fb5b8030bda122a6bbf80c211f945abc07e3
4
+ data.tar.gz: a16b689c9cd2a7105cf0606aca37690d719630ef1ca49298f2be66e4ebfd0fd4
5
5
  SHA512:
6
- metadata.gz: 3096bf0c3448fd39ad6044d1ef6fc2f75b588b941c43eee34621344480a2770cf2f9ac0a1ef62f6100b396349b838a3da93888d6232e711c8603a3910d537e69
7
- data.tar.gz: dfefb60825e0befbf7414998d982526eff206f22a5dbf1638bbda03252d711f5b76f8e3caee8d612a5db4408444bc8517003d7fc3c2e7c58377032fb24e95f1f
6
+ metadata.gz: 2ad3fca95638be67289fc0c424e157c2be84456ff1a52f33b8e0e1c0d104bb98d57606e28b0be6a08c438cce7e7c860f385a5dd06adb4e4180a508a760747241
7
+ data.tar.gz: f0cca01a652a62ce867eeff381ac7053eea305796860cbe7115fbfbfcb5aa0b5446109034f492ff702f825f7bebf55919c112534aac921d42467ce63dd7ef9f4
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GeoStates
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/geo_states.rb CHANGED
@@ -12,20 +12,37 @@ module GeoStates
12
12
  DataLoader.countries
13
13
  end
14
14
 
15
- # Find country by ISO 3166-1 alpha-2 (e.g. "MX", "US").
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").
16
26
  # @param iso2 [String]
17
27
  # @return [Hash, nil]
18
- def self.find_country(iso2)
28
+ def self.find_country_by_iso2(iso2)
19
29
  DataLoader.find_by_iso2(iso2)
20
30
  end
21
31
 
22
- # 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").
23
33
  # @param iso3 [String]
24
34
  # @return [Hash, nil]
25
35
  def self.find_country_by_iso3(iso3)
26
36
  DataLoader.find_by_iso3(iso3)
27
37
  end
28
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
+
29
46
  # Find country by name (case-insensitive).
30
47
  # @param name [String]
31
48
  # @return [Hash, nil]
@@ -33,13 +50,11 @@ module GeoStates
33
50
  DataLoader.find_by_name(name)
34
51
  end
35
52
 
36
- # States for a country (by iso2, iso3, or country name).
37
- # @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
38
55
  # @return [Array<Hash>]
39
56
  def self.states_for(identifier)
40
- country = find_country(identifier) ||
41
- find_country_by_iso3(identifier) ||
42
- find_country_by_name(identifier)
57
+ country = find_country(identifier)
43
58
  country&.dig(:states) || []
44
59
  end
45
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alberto Osnaya (@elosnaya)