From 1bd2bff80a2abdf911570917daa2a0e2e879357b Mon Sep 17 00:00:00 2001 From: "Tyler A. Young" Date: Fri, 30 Aug 2024 18:12:09 -0400 Subject: [PATCH] Apply suggestions from code review --- lib/geo/json/decoder.ex | 21 +++++++++------------ test/geo/json_test.exs | 5 +++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/geo/json/decoder.ex b/lib/geo/json/decoder.ex index 1e36bda..2e17d14 100644 --- a/lib/geo/json/decoder.ex +++ b/lib/geo/json/decoder.ex @@ -197,18 +197,15 @@ defmodule Geo.JSON.Decoder do defp do_decode("Feature", nil, _properties, _id), do: nil defp do_decode("Feature", geometry, properties, _id) do - cond do - - Map.get(geometry, "type") == "GeometryCollection" -> - geometry_collection = decode!(geometry) - - %GeometryCollection{ - geometries: geometry_collection.geometries, - properties: properties - } - - true -> - do_decode(Map.get(geometry, "type"), Map.get(geometry, "coordinates"), properties, nil) + if geometry["type"] == "GeometryCollection" do + geometry_collection = decode!(geometry) + + %GeometryCollection{ + geometries: geometry_collection.geometries, + properties: properties + } + else + do_decode(Map.get(geometry, "type"), Map.get(geometry, "coordinates"), properties, nil) end end diff --git a/test/geo/json_test.exs b/test/geo/json_test.exs index 7a26b1b..a8c5b4e 100644 --- a/test/geo/json_test.exs +++ b/test/geo/json_test.exs @@ -522,8 +522,9 @@ defmodule Geo.JSON.Test do geom = Jason.decode!(json) |> Geo.JSON.decode!() - assert(Enum.count(geom.geometries) == 2) - assert(Enum.each(geom.geometries, fn (%Geo.MultiPolygon{} = g) -> true end)) + assert %GeometryCollection{} = geom + assert length(geom.geometries) == 2 + assert Enum.all?(geom.geometries, &match?(%Geo.MultiPolygon{}, &1)) assert geom.properties["id"] == "FLC017" end end