refactor: AprsSymbol.normalize_symbol_table pattern-matches on input
- Three-way cond (known-table / overlay-capable char / fallback) becomes three function heads: a guard-matched clause for the canonical "/"/"\\"/"]" tables, an is_binary clause that decides via regex match whether the input is a single alphanumeric overlay character, and a catch-all fallback.
This commit is contained in:
parent
2e5034f8c3
commit
9053eef2c6
1 changed files with 10 additions and 5 deletions
|
|
@ -164,14 +164,19 @@ defmodule AprsmeWeb.AprsSymbol do
|
|||
"/"
|
||||
"""
|
||||
@spec normalize_symbol_table(String.t() | nil) :: String.t()
|
||||
def normalize_symbol_table(symbol_table) do
|
||||
cond do
|
||||
symbol_table in ["/", "\\", "]"] -> symbol_table
|
||||
symbol_table && String.match?(symbol_table, ~r/^[A-Z0-9]$/) -> "]"
|
||||
true -> "/"
|
||||
def normalize_symbol_table(table) when table in ["/", "\\", "]"], do: table
|
||||
|
||||
def normalize_symbol_table(table) when is_binary(table) do
|
||||
# A single alphanumeric character is an overlay — map to the overlay table.
|
||||
if String.match?(table, ~r/^[A-Z0-9]$/) do
|
||||
"]"
|
||||
else
|
||||
"/"
|
||||
end
|
||||
end
|
||||
|
||||
def normalize_symbol_table(_), do: "/"
|
||||
|
||||
@doc """
|
||||
Normalizes a symbol code.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue