From 09f239b6b18a8dcf3235390aeb202b20c1eddfc3 Mon Sep 17 00:00:00 2001 From: bdebinska Date: Tue, 18 Nov 2025 15:41:10 +0100 Subject: [PATCH 1/2] Add an optional "separator" field for coordinates --- lib/schemas.ex | 16 +++++++++++----- lib/value_formatters.ex | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/schemas.ex b/lib/schemas.ex index bf69b89..be27fe6 100644 --- a/lib/schemas.ex +++ b/lib/schemas.ex @@ -71,8 +71,13 @@ defmodule ValueFormatters.Schemas do default: true, description: "Whether the formatter should include the radius/accuracy information (if present)." - } + }, + separator: %{ + type: :string, + default: ", ", + description: "The string used to separate latitude, longitude and radius values." } + } end end @@ -114,7 +119,7 @@ defmodule ValueFormatters.Schemas.Format do type: :string, description: "If the value is an object, the field to extract the formattable entity from." - } + }, }, required: [:format], additionalProperties: false @@ -238,7 +243,7 @@ defmodule ValueFormatters.Schemas.Format do type: :string, description: "If the value is an object, the field to extract the formattable entity from." - } + }, }, coordinates_options() ), @@ -253,10 +258,11 @@ defmodule ValueFormatters.Schemas.Format do type: :string, description: "If the value is an object, the field to extract the formattable entity from." - } + }, + }, required: [:field], - additionalProperties: false + additionalProperties: true } ] } diff --git a/lib/value_formatters.ex b/lib/value_formatters.ex index e9c0e96..aead974 100644 --- a/lib/value_formatters.ex +++ b/lib/value_formatters.ex @@ -365,6 +365,7 @@ defmodule ValueFormatters do format_number(lat, %{"format" => "number", "precision" => 5}, opts), {:ok, lng_formatted} <- format_number(lng, %{"format" => "number", "precision" => 5}, opts) do + separator = get_in(coordinate_definition, ["separator"]) || ", " if get_in(coordinate_definition, ["radius_display"]) != false and radius != nil do with {:ok, radius_formatted} <- format_number( @@ -372,12 +373,12 @@ defmodule ValueFormatters do %{"format" => "number", "precision" => 0, "unit" => "m"}, opts ) do - {:ok, "#{lat_formatted}\u{00B0}, #{lng_formatted}\u{00B0}, #{radius_formatted}"} + {:ok, "#{lat_formatted}\u{00B0}#{separator}#{lng_formatted}\u{00B0}#{separator}#{radius_formatted}"} else {:error, reason} -> {:error, reason} end else - {:ok, "#{lat_formatted}\u{00B0}, #{lng_formatted}\u{00B0}"} + {:ok, "#{lat_formatted}\u{00B0}#{separator}#{lng_formatted}\u{00B0}"} end else {:error, _reason} -> {:error, "Value #{value} cannot be parsed as a coordinate"} From f797f6c0fabce4bcfdc7f3c788839381e902fdd5 Mon Sep 17 00:00:00 2001 From: bdebinska Date: Tue, 18 Nov 2025 15:47:11 +0100 Subject: [PATCH 2/2] Run mix.format --- lib/schemas.ex | 9 ++++----- lib/value_formatters.ex | 4 +++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/schemas.ex b/lib/schemas.ex index be27fe6..573bee2 100644 --- a/lib/schemas.ex +++ b/lib/schemas.ex @@ -76,8 +76,8 @@ defmodule ValueFormatters.Schemas do type: :string, default: ", ", description: "The string used to separate latitude, longitude and radius values." + } } - } end end @@ -119,7 +119,7 @@ defmodule ValueFormatters.Schemas.Format do type: :string, description: "If the value is an object, the field to extract the formattable entity from." - }, + } }, required: [:format], additionalProperties: false @@ -243,7 +243,7 @@ defmodule ValueFormatters.Schemas.Format do type: :string, description: "If the value is an object, the field to extract the formattable entity from." - }, + } }, coordinates_options() ), @@ -258,8 +258,7 @@ defmodule ValueFormatters.Schemas.Format do type: :string, description: "If the value is an object, the field to extract the formattable entity from." - }, - + } }, required: [:field], additionalProperties: true diff --git a/lib/value_formatters.ex b/lib/value_formatters.ex index aead974..9817ba2 100644 --- a/lib/value_formatters.ex +++ b/lib/value_formatters.ex @@ -366,6 +366,7 @@ defmodule ValueFormatters do {:ok, lng_formatted} <- format_number(lng, %{"format" => "number", "precision" => 5}, opts) do separator = get_in(coordinate_definition, ["separator"]) || ", " + if get_in(coordinate_definition, ["radius_display"]) != false and radius != nil do with {:ok, radius_formatted} <- format_number( @@ -373,7 +374,8 @@ defmodule ValueFormatters do %{"format" => "number", "precision" => 0, "unit" => "m"}, opts ) do - {:ok, "#{lat_formatted}\u{00B0}#{separator}#{lng_formatted}\u{00B0}#{separator}#{radius_formatted}"} + {:ok, + "#{lat_formatted}\u{00B0}#{separator}#{lng_formatted}\u{00B0}#{separator}#{radius_formatted}"} else {:error, reason} -> {:error, reason} end