From 9053eef2c67d342872716fe1f2b888a622317189 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 23 Apr 2026 14:29:12 -0500 Subject: [PATCH] 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. --- lib/aprsme_web/aprs_symbol.ex | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/aprsme_web/aprs_symbol.ex b/lib/aprsme_web/aprs_symbol.ex index 8adb715..33786d3 100644 --- a/lib/aprsme_web/aprs_symbol.ex +++ b/lib/aprsme_web/aprs_symbol.ex @@ -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.