From 81d768f1c01e92eb5d6382222c62a3764f2c2b58 Mon Sep 17 00:00:00 2001 From: CoslaJohn Date: Fri, 9 Feb 2024 14:36:02 +0000 Subject: [PATCH] Refactor regex in normalized_coordinates method to allow for whitespace between square brackets --- app/models/geozone.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/geozone.rb b/app/models/geozone.rb index be2930ca8..eddf5a13f 100644 --- a/app/models/geozone.rb +++ b/app/models/geozone.rb @@ -28,9 +28,10 @@ class Geozone < ApplicationRecord def normalized_coordinates if geojson.present? - if geojson.match(/"coordinates"\s*:\s*\[{4}/) + if geojson.match(/"coordinates"\s*:\s*\[\s*\[\s*\[\s*\[/) coordinates.reduce([], :concat).reduce([], :concat) - elsif geojson.match(/"coordinates"\s*:\s*\[{3}/) + elsif geojson.match(/"coordinates"\s*:\s*\[\s*\[\s*\[/) + coordinates.reduce([], :concat) else coordinates @@ -39,7 +40,7 @@ class Geozone < ApplicationRecord [] end end - + def coordinates JSON.parse(geojson)["geometry"]["coordinates"] end