From 09f239b6b18a8dcf3235390aeb202b20c1eddfc3 Mon Sep 17 00:00:00 2001 From: bdebinska Date: Tue, 18 Nov 2025 15:41:10 +0100 Subject: [PATCH 1/3] 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/3] 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 From 2f5572babb5d9ea48ceefcc777e3a498ec153ef1 Mon Sep 17 00:00:00 2001 From: bdebinska Date: Tue, 18 Nov 2025 16:06:05 +0100 Subject: [PATCH 3/3] Bump version to 0.2.2 and update changelog --- CHANGELOG.md | 18 ++++++++++++------ mix.exs | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76c4213..2926617 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Unreleased changes will be displayed here upon implementation. -## [0.2.0] - 2025-08-13 - -### Added +## [0.2.2] - 2025-11-15 -- [JSV](https://hexdocs.pm/jsv/JSV.html)-compatible JsonSchema definitions for `format` and `defaults` as - `ValueFormatter.Schema.Format` and `ValueFormatter.Schema.DefaultFormats`, respectively. +### Added +- Added support for custom coordinate separators in coordinate formatting. ## [0.2.1] - 2025-10-28 @@ -22,5 +20,13 @@ Unreleased changes will be displayed here upon implementation. - Minor documentation fixes and improvements. -[unreleased]: https://github.com/box-id/value_formatters/compare/0.2.1...HEAD +## [0.2.0] - 2025-08-13 + +### Added + +- [JSV](https://hexdocs.pm/jsv/JSV.html)-compatible JsonSchema definitions for `format` and `defaults` as + `ValueFormatter.Schema.Format` and `ValueFormatter.Schema.DefaultFormats`, respectively. + +[unreleased]: https://github.com/box-id/value_formatters/compare/0.2.2...HEAD +[0.2.2]: https://github.com/box-id/value_formatters/releases/tag/0.2.2 [0.2.1]: https://github.com/box-id/value_formatters/releases/tag/0.2.1 diff --git a/mix.exs b/mix.exs index d4fd4a3..3e2dd81 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule ValueFormatters.MixProject do def project do [ app: :value_formatters, - version: "0.2.1", + version: "0.2.2", elixir: "~> 1.15", elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod,