Skip to content

Commit

Permalink
Merge pull request #41 from kipcole9/master
Browse files Browse the repository at this point in the history
mix format
  • Loading branch information
kipcole9 authored Sep 28, 2024
2 parents 1ba1cfa + 9d9610d commit 7cdefdb
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 73 deletions.
1 change: 0 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
import Config

21 changes: 11 additions & 10 deletions lib/mix/tasks/update_timezones_geojson.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ defmodule Mix.Tasks.TzWorld.Update do

_other ->
Mix.raise(
"""
Invalid arguments found. `mix tz_world.update` accepts the following:
--include-oceans
--no-include-oceans (default)
--force
--no-force (default)
--trace
--no-trace (default)
""",
exit_status: 1)
"""
Invalid arguments found. `mix tz_world.update` accepts the following:
--include-oceans
--no-include-oceans (default)
--force
--no-force (default)
--trace
--no-trace (default)
""",
exit_status: 1
)
end
end

Expand Down
19 changes: 10 additions & 9 deletions lib/tz_world.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule TzWorld do
TzWorld.Backend.Dets,
TzWorld.Backend.DetsWithIndexCache,
TzWorld.Backend.Ets,
TzWorld.Backend.EtsWithIndexCache,
TzWorld.Backend.EtsWithIndexCache
]

@doc """
Expand Down Expand Up @@ -99,7 +99,7 @@ defmodule TzWorld do
"""
@spec timezone_at(Geo.Point.t(), backend) ::
{:ok, String.t()} | {:error, atom}
{:ok, String.t()} | {:error, atom}

def timezone_at(point, backend \\ fetch_backend())

Expand All @@ -108,15 +108,15 @@ defmodule TzWorld do
end

@spec timezone_at(Geo.PointZ.t(), backend) ::
{:ok, String.t()} | {:error, atom}
{:ok, String.t()} | {:error, atom}

def timezone_at(%PointZ{coordinates: {lng, lat, _alt}}, backend) when is_atom(backend) do
point = %Point{coordinates: {lng, lat}}
backend.timezone_at(point)
end

@spec timezone_at({lng :: number, lat :: number}, backend) ::
{:ok, String.t()} | {:error, atom}
{:ok, String.t()} | {:error, atom}

def timezone_at({lng, lat}, backend) when is_lng(lng) and is_lat(lat) do
point = %Geo.Point{coordinates: {lng, lat}}
Expand Down Expand Up @@ -171,7 +171,7 @@ defmodule TzWorld do
"""
@spec all_timezones_at(Geo.Point.t(), backend) ::
{:ok, [String.t()]}
{:ok, [String.t()]}

def all_timezones_at(point, backend \\ fetch_backend())

Expand All @@ -180,15 +180,15 @@ defmodule TzWorld do
end

@spec all_timezones_at(Geo.PointZ.t(), backend) ::
{:ok, [String.t()]}
{:ok, [String.t()]}

def all_timezones_at(%PointZ{coordinates: {lng, lat, _alt}}, backend) when is_atom(backend) do
point = %Point{coordinates: {lng, lat}}
backend.all_timezones_at(point)
end

@spec all_timezones_at({lng :: number, lat :: number}, backend) ::
{:ok, [String.t()]}
{:ok, [String.t()]}

def all_timezones_at({lng, lat}, backend) when is_lng(lng) and is_lat(lat) do
point = %Geo.Point{coordinates: {lng, lat}}
Expand Down Expand Up @@ -246,9 +246,10 @@ defmodule TzWorld do
|> Enum.reject(&is_nil/1)

Enum.find(backends, &Process.whereis/1) ||
raise(RuntimeError,
raise(
RuntimeError,
"No TzWorld backend appears to be running. " <>
"please add one of #{inspect backends} to your supervision tree"
"please add one of #{inspect(backends)} to your supervision tree"
)
end

Expand Down
1 change: 0 additions & 1 deletion lib/tz_world/backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ defmodule TzWorld.Backend do
Reloads the (potentially updated) timezone data
"""
@callback reload_timezone_data :: {:ok, term}

end
17 changes: 9 additions & 8 deletions lib/tz_world/backend/dets.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ defmodule TzWorld.Backend.Dets do
@doc false
def handle_continue(:open_dets_file, _state) do
case get_geodata_table() do
{:error, {:file_error, _, :enoent}} ->
{:noreply, {:error, :enoent}}
{:error, {:not_closed, _path}} ->
raise "NOT CLOSED"
{:ok, __MODULE__} ->
{:noreply, {:ok, __MODULE__}}
{:error, {:file_error, _, :enoent}} ->
{:noreply, {:error, :enoent}}

{:error, {:not_closed, _path}} ->
raise "NOT CLOSED"

{:ok, __MODULE__} ->
{:noreply, {:ok, __MODULE__}}
end
end

Expand Down Expand Up @@ -112,7 +114,7 @@ defmodule TzWorld.Backend.Dets do
point
|> select_candidates()
|> Enum.filter(&TzWorld.contains?(&1, point))
|> Enum.map(&(&1.properties.tzid))
|> Enum.map(& &1.properties.tzid)
|> wrap(:ok)
end

Expand Down Expand Up @@ -200,5 +202,4 @@ defmodule TzWorld.Backend.Dets do
defp dets_options do
[file: filename(), access: :read, estimated_no_objects: @slots]
end

end
11 changes: 6 additions & 5 deletions lib/tz_world/backend/dets_with_index_cache.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ defmodule TzWorld.Backend.DetsWithIndexCache do
@doc false
def handle_continue(:open_dets_file, _state) do
case get_geodata_table() do
{:error, {:file_error, _, :enoent}} ->
{:noreply, {:error, :enoent}}
{:ok, __MODULE__} ->
{:noreply, get_index_cache()}
{:error, {:file_error, _, :enoent}} ->
{:noreply, {:error, :enoent}}

{:ok, __MODULE__} ->
{:noreply, get_index_cache()}
end
end

Expand Down Expand Up @@ -162,7 +163,7 @@ defmodule TzWorld.Backend.DetsWithIndexCache do
point
|> select_candidates(state)
|> Enum.filter(&TzWorld.contains?(&1, point))
|> Enum.map(&(&1.properties.tzid))
|> Enum.map(& &1.properties.tzid)
|> wrap(:ok)
end

Expand Down
3 changes: 1 addition & 2 deletions lib/tz_world/backend/ets.ex
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ defmodule TzWorld.Backend.Ets do
point
|> select_candidates()
|> Enum.filter(&TzWorld.contains?(&1, point))
|> Enum.map(&(&1.properties.tzid))
|> Enum.map(& &1.properties.tzid)
|> wrap(:ok)
end

Expand All @@ -112,5 +112,4 @@ defmodule TzWorld.Backend.Ets do
nil -> {:error, :time_zone_not_found}
end
end

end
2 changes: 1 addition & 1 deletion lib/tz_world/backend/ets_with_index_cache.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ defmodule TzWorld.Backend.EtsWithIndexCache do
point
|> select_candidates(state)
|> Enum.filter(&TzWorld.contains?(&1, point))
|> Enum.map(&(&1.properties.tzid))
|> Enum.map(& &1.properties.tzid)
|> wrap(:ok)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tz_world/backend/memory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ defmodule TzWorld.Backend.Memory do
tz_data
|> Enum.filter(&TzWorld.contains?(&1.properties.bounding_box, point))
|> Enum.filter(&TzWorld.contains?(&1, point))
|> Enum.map(&(&1.properties.tzid))
|> Enum.map(& &1.properties.tzid)
|> wrap(:ok)
end

Expand Down
Loading

0 comments on commit 7cdefdb

Please sign in to comment.