Skip to content

Commit

Permalink
from_json should not recognize empty strings as a match
Browse files Browse the repository at this point in the history
  • Loading branch information
dealloc committed Mar 3, 2024
1 parent df221ff commit 2797595
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/helldivers_2/macros/from_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ defmodule Helldivers2.Macros.FromJson do
|> Jason.decode!()

for {key, value} <- mappings do
quote do
defp lookup("#{unquote(key)}"), do: unquote(value)
if String.length(value) > 0 do
quote do
defp lookup("#{unquote(key)}"), do: unquote(value)
end
else
quote do
defp lookup("#{unquote(key)}"), do: unquote(key)
end
end
end ++
[
Expand Down
2 changes: 1 addition & 1 deletion lib/helldivers_2/models/war_info/sector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ defmodule Helldivers2.Models.WarInfo.Sector do
@spec parse(non_neg_integer() | String.t()) :: t()
def parse(index) when is_number(index), do: parse(to_string(index))
def parse(name), do: lookup(name)
defp lookup(_), do: "Unknown"
defp lookup(index), do: index
end

0 comments on commit 2797595

Please sign in to comment.