Module: NaturalEarth::ISO3166
- Included in:
- Countries, Geometries, Subdivisions
- Defined in:
- lib/natural_earth/iso3166.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#as_iso3166_1(iso3166) ⇒ Object
Normalize an ISO-3166-1 code (alpha-2, alpha-3 or numeric) or ISO-3166-2 code to ISO-3166 alpha-2.
-
#as_iso3166_2(iso3166) ⇒ Object
Normalize an ISO-3166-2 code.
Instance Method Details
#as_iso3166_1(iso3166) ⇒ Object
Normalize an ISO-3166-1 code (alpha-2, alpha-3 or numeric) or ISO-3166-2 code to ISO-3166 alpha-2
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/natural_earth/iso3166.rb', line 6 def as_iso3166_1(iso3166) return numeric_to_alpha2(iso3166) if numeric? iso3166 normalized = extract(reformat(iso3166)) raise ArgumentError if normalized.length > 3 || normalized.length < 2 return alpha3_to_alpha2(normalized) if normalized.length == 3 normalized end |
#as_iso3166_2(iso3166) ⇒ Object
Normalize an ISO-3166-2 code
18 19 20 21 22 23 |
# File 'lib/natural_earth/iso3166.rb', line 18 def as_iso3166_2(iso3166) normalized = reformat(iso3166) raise ArgumentError unless normalized.match?(/\A[A-Z]{2}-[A-Z0-9]+\z/) normalized end |