Cadastre.Subdivision (Cadastre v0.2.12) View Source

Subdivision implementation.

Link to this section Summary

Functions

Returns subdivisions for country or empty list for invalid argument.

Returns all subdivision ids (ISO_3166-2) for country or empty list for invalid argument.

Returns subdivision name translation for locale.

Returns %Cadastre.Subdivision{} for valid country/country_id and id or nil for invalid country/country_id and id.

Link to this section Types

Specs

id() :: String.t()

Specs

t() :: %Cadastre.Subdivision{country_id: Cadastre.Country.id(), id: id()}

Link to this section Functions

Link to this function

all(country_or_country_id)

View Source

Specs

Returns subdivisions for country or empty list for invalid argument.

Examples

iex> Cadastre.Subdivision.all("SL")
[
  %Cadastre.Subdivision{country_id: "SL", id: "E"},
  %Cadastre.Subdivision{country_id: "SL", id: "N"},
  %Cadastre.Subdivision{country_id: "SL", id: "NW"},
  %Cadastre.Subdivision{country_id: "SL", id: "S"},
  %Cadastre.Subdivision{country_id: "SL", id: "W"}
]

iex> "SL" |> Cadastre.Country.new() |> Cadastre.Subdivision.all()
[
  %Cadastre.Subdivision{country_id: "SL", id: "E"},
  %Cadastre.Subdivision{country_id: "SL", id: "N"},
  %Cadastre.Subdivision{country_id: "SL", id: "NW"},
  %Cadastre.Subdivision{country_id: "SL", id: "S"},
  %Cadastre.Subdivision{country_id: "SL", id: "W"}
]

iex> Cadastre.Subdivision.all("XX")
[]

iex> Cadastre.Subdivision.all(nil)
[]
Link to this function

ids(country_or_country_id)

View Source

Specs

Returns all subdivision ids (ISO_3166-2) for country or empty list for invalid argument.

Examples

iex> Cadastre.Subdivision.ids("SL")
["E", "N", "NW", "S", "W"]

iex> "SL" |> Cadastre.Country.new() |> Cadastre.Subdivision.ids()
["E", "N", "NW", "S", "W"]

iex> Cadastre.Subdivision.ids("XX")
[]

iex> Cadastre.Subdivision.ids(nil)
[]
Link to this function

name(subdivision, locale)

View Source

Specs

name(t(), Cadastre.Language.id()) :: String.t()

Returns subdivision name translation for locale.

Examples

iex> Cadastre.Subdivision.new("SL", "W") |> Cadastre.Subdivision.name("be")
"Заходняя вобласць"

iex> Cadastre.Subdivision.new("SL", "W") |> Cadastre.Subdivision.name(":)")
"Western Area (Freetown)"

iex> Cadastre.Subdivision.name("something wrong", "be")
nil
Link to this function

new(country_or_country_id, id)

View Source

Specs

new(Cadastre.Country.t() | Cadastre.Country.id() | any(), id() | any()) ::
  t() | nil

Returns %Cadastre.Subdivision{} for valid country/country_id and id or nil for invalid country/country_id and id.

Examples

iex> Cadastre.Subdivision.new("SL", "W")
%Cadastre.Subdivision{country_id: "SL", id: "W"}

iex> Cadastre.Subdivision.new("sl", "w")
%Cadastre.Subdivision{country_id: "SL", id: "W"}

iex> "SL" |> Cadastre.Country.new() |> Cadastre.Subdivision.new("W")
%Cadastre.Subdivision{country_id: "SL", id: "W"}

iex> Cadastre.Subdivision.new("NL", "W")
nil

iex> Cadastre.Subdivision.new("SL", "X")
nil

iex> Cadastre.Subdivision.new(nil, nil)
nil