View Source Place (Place v0.1.1)

Query API and GenServer for Place, a dataset of countries, states and cities around the world.

Summary

Functions

Returns a specification to start this module under a supervisor.

Get an unordered list of all cities by the given country code, and optional state code.

Like get_cities/1 but takes a %Place.DB{} as the first argument.

Get a city by the given country code, state code and city name.

Like get_city/1 but takes a %Place.DB{} as the first argument.

Get an unordered list of all countries.

Like get_countries/0 but takes a %Place.DB{} as the first argument.

Get a country by the given country code.

Like get_country/1 but takes a %Place.DB{} as the first argument.

Get a state by the given country code and state code.

Like get_state/1 but takes a %Place.DB{} as the first argument.

Get an unordered list of all states by the given country code.

Like get_states/1 but takes a %Place.DB{} as the first argument.

Check if the country by the given country code has any states.

Like has_states?/1 but takes a %Place.DB{} as the first argument.

Reads and deserializes the database file into a %Place.DB{} struct.

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec get_cities([{:country_code, binary()}]) :: [Place.City.t()]
@spec get_cities(country_code: binary(), state_code: binary()) :: [Place.City.t()]

Get an unordered list of all cities by the given country code, and optional state code.

Options

Examples

iex> cities = Place.get_cities(country_code: "US")
iex> Enum.find(cities, &(&1.name == "Los Angeles")).latitude
"34.05223000"

iex> cities = Place.get_cities(country_code: "US", state_code: "CA")
iex> Enum.find(cities, &(&1.name == "Los Angeles")).latitude
"34.05223000"
@spec get_cities(Place.DB.t(), [{:country_code, binary()}]) :: [Place.City.t()]
@spec get_cities(Place.DB.t(), country_code: binary(), state_code: binary()) :: [
  Place.City.t()
]

Like get_cities/1 but takes a %Place.DB{} as the first argument.

Examples

iex> db = Place.load_db!()
iex> cities = Place.get_cities(db, country_code: "US")
iex> Enum.find(cities, &(&1.name == "Los Angeles")).latitude
"34.05223000"

iex> db = Place.load_db!()
iex> cities = Place.get_cities(db, country_code: "US", state_code: "CA")
iex> Enum.find(cities, &(&1.name == "Los Angeles")).latitude
"34.05223000"
@spec get_city(country_code: binary(), state_code: binary(), city_name: binary()) ::
  Place.City.t() | nil

Get a city by the given country code, state code and city name.

Options

  • :country_code - An ISO 3166-1 alpha-2 country code.
  • :state_code - A state code.
  • :city_name - A city name.

Examples

iex> Place.get_city(country_code: "US", state_code: "CA", city_name: "Los Angeles").latitude
"34.05223000"
@spec get_city(Place.DB.t(),
  country_code: binary(),
  state_code: binary(),
  city_name: binary()
) ::
  Place.City.t() | nil

Like get_city/1 but takes a %Place.DB{} as the first argument.

Examples

iex> db = Place.load_db!()
iex> Place.get_city(db, country_code: "US", state_code: "CA", city_name: "Los Angeles").latitude
"34.05223000"
@spec get_countries() :: [Place.Country.t(), ...]

Get an unordered list of all countries.

Examples

iex> countries = Place.get_countries()
iex> Enum.find(countries, &(&1.iso2 == "US")).name
"United States"
@spec get_countries(Place.DB.t()) :: [Place.Country.t(), ...]

Like get_countries/0 but takes a %Place.DB{} as the first argument.

Examples

iex> db = Place.load_db!()
iex> countries = Place.get_countries(db)
iex> Enum.find(countries, &(&1.iso2 == "US")).name
"United States"
@spec get_country([{:country_code, binary()}]) :: Place.Country.t() | nil

Get a country by the given country code.

Options

Examples

iex> Place.get_country(country_code: "US").name
"United States"
@spec get_country(Place.DB.t(), [{:country_code, binary()}]) ::
  Place.Country.t() | nil

Like get_country/1 but takes a %Place.DB{} as the first argument.

Examples

iex> db = Place.load_db!()
iex> Place.get_country(db, country_code: "US").name
"United States"
@spec get_state(country_code: binary(), state_code: binary()) :: Place.State.t() | nil

Get a state by the given country code and state code.

Options

Examples

iex> Place.get_state(country_code: "US", state_code: "CA").name
"California"
@spec get_state(Place.DB.t(), country_code: binary(), state_code: binary()) ::
  Place.State.t() | nil

Like get_state/1 but takes a %Place.DB{} as the first argument.

Examples

iex> db = Place.load_db!()
iex> Place.get_state(db, country_code: "US", state_code: "CA").name
"California"
@spec get_states([{:country_code, binary()}]) :: [Place.State.t()]

Get an unordered list of all states by the given country code.

Options

Examples

iex> states = Place.get_states(country_code: "US")
iex> Enum.find(states, &(&1.state_code == "CA")).name
"California"
@spec get_states(Place.DB.t(), [{:country_code, binary()}]) :: [Place.State.t()]

Like get_states/1 but takes a %Place.DB{} as the first argument.

Examples

iex> db = Place.load_db!()
iex> states = Place.get_states(db, country_code: "US")
iex> Enum.find(states, &(&1.state_code == "CA")).name
"California"
@spec has_states?([{:country_code, binary()}]) :: {:ok, boolean()} | {:error, false}

Check if the country by the given country code has any states.

Options

Examples

iex> Place.has_states?(country_code: "US")
{:ok, true}
@spec has_states?(Place.DB.t(), [{:country_code, binary()}]) ::
  {:ok, boolean()} | {:error, false}

Like has_states?/1 but takes a %Place.DB{} as the first argument.

Examples

iex> db = Place.load_db!()
iex> Place.has_states?(db, country_code: "US")
{:ok, true}
@spec load_db!() :: Place.DB.t()

Reads and deserializes the database file into a %Place.DB{} struct.

Examples

iex> db = Place.load_db!()
iex> Enum.count(db.countries)
250