fix: convert WeatherUnits module attribute to runtime function to fix compile-connected xref
This commit is contained in:
parent
7bf0eecfbe
commit
8b62afa36b
1 changed files with 13 additions and 11 deletions
|
|
@ -212,15 +212,17 @@ defmodule AprsmeWeb.WeatherLive.CallsignView do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Weather formatters mapping
|
# Weather formatters mapping (runtime function to avoid compile-time dependency)
|
||||||
@weather_formatters %{
|
defp weather_formatters do
|
||||||
temperature: {&WeatherUnits.format_temperature/2, ""},
|
%{
|
||||||
wind_speed: {&WeatherUnits.format_wind_speed/2, " "},
|
temperature: {&WeatherUnits.format_temperature/2, ""},
|
||||||
wind_gust: {&WeatherUnits.format_wind_speed/2, " "},
|
wind_speed: {&WeatherUnits.format_wind_speed/2, " "},
|
||||||
rain_1h: {&WeatherUnits.format_rain/2, " "},
|
wind_gust: {&WeatherUnits.format_wind_speed/2, " "},
|
||||||
rain_24h: {&WeatherUnits.format_rain/2, " "},
|
rain_1h: {&WeatherUnits.format_rain/2, " "},
|
||||||
rain_since_midnight: {&WeatherUnits.format_rain/2, " "}
|
rain_24h: {&WeatherUnits.format_rain/2, " "},
|
||||||
}
|
rain_since_midnight: {&WeatherUnits.format_rain/2, " "}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Checks if a weather field has a valid value (not nil, "N/A", or empty).
|
Checks if a weather field has a valid value (not nil, "N/A", or empty).
|
||||||
|
|
@ -254,7 +256,7 @@ defmodule AprsmeWeb.WeatherLive.CallsignView do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp format_string_value(value, key, locale) do
|
defp format_string_value(value, key, locale) do
|
||||||
case @weather_formatters[key] do
|
case weather_formatters()[key] do
|
||||||
{formatter, separator} ->
|
{formatter, separator} ->
|
||||||
case Float.parse(value) do
|
case Float.parse(value) do
|
||||||
{num_value, _} ->
|
{num_value, _} ->
|
||||||
|
|
@ -271,7 +273,7 @@ defmodule AprsmeWeb.WeatherLive.CallsignView do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp format_numeric_value(value, key, locale) do
|
defp format_numeric_value(value, key, locale) do
|
||||||
case @weather_formatters[key] do
|
case weather_formatters()[key] do
|
||||||
{formatter, separator} ->
|
{formatter, separator} ->
|
||||||
{converted_value, unit} = formatter.(value, locale)
|
{converted_value, unit} = formatter.(value, locale)
|
||||||
"#{converted_value}#{separator}#{unit}"
|
"#{converted_value}#{separator}#{unit}"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue