Skip to content

Commit 91ca202

Browse files
authored
Add an optional "separator" field for coordinates (#8)
1 parent ab7c0f8 commit 91ca202

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/schemas.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ defmodule ValueFormatters.Schemas do
7171
default: true,
7272
description:
7373
"Whether the formatter should include the radius/accuracy information (if present)."
74+
},
75+
separator: %{
76+
type: :string,
77+
default: ", ",
78+
description: "The string used to separate latitude, longitude and radius values."
7479
}
7580
}
7681
end
@@ -256,7 +261,7 @@ defmodule ValueFormatters.Schemas.Format do
256261
}
257262
},
258263
required: [:field],
259-
additionalProperties: false
264+
additionalProperties: true
260265
}
261266
]
262267
}

lib/value_formatters.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,19 +365,22 @@ defmodule ValueFormatters do
365365
format_number(lat, %{"format" => "number", "precision" => 5}, opts),
366366
{:ok, lng_formatted} <-
367367
format_number(lng, %{"format" => "number", "precision" => 5}, opts) do
368+
separator = get_in(coordinate_definition, ["separator"]) || ", "
369+
368370
if get_in(coordinate_definition, ["radius_display"]) != false and radius != nil do
369371
with {:ok, radius_formatted} <-
370372
format_number(
371373
radius,
372374
%{"format" => "number", "precision" => 0, "unit" => "m"},
373375
opts
374376
) do
375-
{:ok, "#{lat_formatted}\u{00B0}, #{lng_formatted}\u{00B0}, #{radius_formatted}"}
377+
{:ok,
378+
"#{lat_formatted}\u{00B0}#{separator}#{lng_formatted}\u{00B0}#{separator}#{radius_formatted}"}
376379
else
377380
{:error, reason} -> {:error, reason}
378381
end
379382
else
380-
{:ok, "#{lat_formatted}\u{00B0}, #{lng_formatted}\u{00B0}"}
383+
{:ok, "#{lat_formatted}\u{00B0}#{separator}#{lng_formatted}\u{00B0}"}
381384
end
382385
else
383386
{:error, _reason} -> {:error, "Value #{value} cannot be parsed as a coordinate"}

0 commit comments

Comments
 (0)