Skip to content

Commit 09f239b

Browse files
committed
Add an optional "separator" field for coordinates
1 parent ab7c0f8 commit 09f239b

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/schemas.ex

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ defmodule ValueFormatters.Schemas do
7171
default: true,
7272
description:
7373
"Whether the formatter should include the radius/accuracy information (if present)."
74-
}
74+
},
75+
separator: %{
76+
type: :string,
77+
default: ", ",
78+
description: "The string used to separate latitude, longitude and radius values."
7579
}
80+
}
7681
end
7782
end
7883

@@ -114,7 +119,7 @@ defmodule ValueFormatters.Schemas.Format do
114119
type: :string,
115120
description:
116121
"If the value is an object, the field to extract the formattable entity from."
117-
}
122+
},
118123
},
119124
required: [:format],
120125
additionalProperties: false
@@ -238,7 +243,7 @@ defmodule ValueFormatters.Schemas.Format do
238243
type: :string,
239244
description:
240245
"If the value is an object, the field to extract the formattable entity from."
241-
}
246+
},
242247
},
243248
coordinates_options()
244249
),
@@ -253,10 +258,11 @@ defmodule ValueFormatters.Schemas.Format do
253258
type: :string,
254259
description:
255260
"If the value is an object, the field to extract the formattable entity from."
256-
}
261+
},
262+
257263
},
258264
required: [:field],
259-
additionalProperties: false
265+
additionalProperties: true
260266
}
261267
]
262268
}

lib/value_formatters.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,19 +365,20 @@ 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"]) || ", "
368369
if get_in(coordinate_definition, ["radius_display"]) != false and radius != nil do
369370
with {:ok, radius_formatted} <-
370371
format_number(
371372
radius,
372373
%{"format" => "number", "precision" => 0, "unit" => "m"},
373374
opts
374375
) do
375-
{:ok, "#{lat_formatted}\u{00B0}, #{lng_formatted}\u{00B0}, #{radius_formatted}"}
376+
{:ok, "#{lat_formatted}\u{00B0}#{separator}#{lng_formatted}\u{00B0}#{separator}#{radius_formatted}"}
376377
else
377378
{:error, reason} -> {:error, reason}
378379
end
379380
else
380-
{:ok, "#{lat_formatted}\u{00B0}, #{lng_formatted}\u{00B0}"}
381+
{:ok, "#{lat_formatted}\u{00B0}#{separator}#{lng_formatted}\u{00B0}"}
381382
end
382383
else
383384
{:error, _reason} -> {:error, "Value #{value} cannot be parsed as a coordinate"}

0 commit comments

Comments
 (0)