-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: parse all elevator redundancy categories
Rather than only storing whether an elevator's redundancy category is "nearby", we now store all categories, including any associated summary text. This is a prerequisite for displaying redundancy summaries on the system-wide outages view. Also extracts this logic into a dedicated module which can be mocked for testing, removing the need for a separate fixture file.
- Loading branch information
1 parent
c584592
commit cf53232
Showing
10 changed files
with
1,134 additions
and
846 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
defmodule Screens.Elevator do | ||
@moduledoc """ | ||
Exposes hand-authored data about elevator accessibility that is currently owned by the Screens | ||
team and not (yet?) available in GTFS. | ||
""" | ||
|
||
alias Screens.Facilities.Facility | ||
|
||
@enforce_keys ~w[id redundancy]a | ||
defstruct @enforce_keys | ||
|
||
@type t :: %__MODULE__{id: Facility.id(), redundancy: redundancy()} | ||
|
||
@type redundancy :: | ||
:nearby | ||
| :in_station | ||
| {:different_station, summary :: String.t()} | ||
| {:contact, summary :: String.t()} | ||
|
||
@data :screens | ||
|> :code.priv_dir() | ||
|> Path.join("elevators.json") | ||
|> File.read!() | ||
|> Jason.decode!() | ||
|
||
@callback get(Facility.id()) :: t() | nil | ||
def get(id) do | ||
case Map.get(@data, id) do | ||
%{"redundancy" => 1} -> | ||
%__MODULE__{id: id, redundancy: :nearby} | ||
|
||
%{"redundancy" => 2} -> | ||
%__MODULE__{id: id, redundancy: :in_station} | ||
|
||
%{"redundancy" => 3, "summary" => summary} -> | ||
%__MODULE__{id: id, redundancy: {:different_station, summary}} | ||
|
||
%{"redundancy" => 4, "summary" => summary} -> | ||
%__MODULE__{id: id, redundancy: {:contact, summary}} | ||
|
||
_other -> | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.