Packages

Countries is a collection of all sorts of useful information for every country in the [ISO 3166](https://de.wikipedia.org/wiki/ISO_3166) standard.

Current section

Files

Jump to
countries lib subdivisions.ex
Raw

lib/subdivisions.ex

defmodule Countries.Subdivisions do
def all(country) do
subdivisions(country.alpha2)
end
# Ensure :yamerl is running
Application.start(:yamerl)
defp subdivisions(country_code) do
data_path = fn(path) ->
Path.join("data", path) |> Path.expand(__DIR__)
end
try do
data_path.("subdivisions/#{country_code}.yaml") |> :yamerl.decode_file |> List.first
catch
_exception -> []
end
end
end