diff --git a/README.md b/README.md index 8116da2..5dcae8e 100644 --- a/README.md +++ b/README.md @@ -99,15 +99,7 @@ Result: # Miscelaneous transformations - `typeOf`: returns type representation of the data (e.g. `str`, `int`, `float`, etc.) -- `strToLocation`: given a latitude and a longitude, it returns an array to build a location. Example: `"value1, value2"|strToLocation`. Example: `"value1, value2"|strToLocation` returns `[value1, value2]`, so we can use this: - -```json -{ - "init": null, - "type": "geo:json", - "exp": "{coordinates:(point|strToLocation),type: \"Point\"}" -} -``` +- `strToLocation`: given a string with a comma separated list of decimal numbers, returns an array of such numbers. Example: `"value1, value2"|strToLocation`. Example: `"value1, value2"|strToLocation` returns `[value1, value2]`. It's name (maybe not very good :) is due to it can be useful to generate a [GeoJSON](https://geojson.org/) representing a point which coordinates are provided in a string, eg: `{coordinates:(point|strToLocation),type: "Point"}` ## Packaging diff --git a/tests/test_transforms_misc.py b/tests/test_transforms_misc.py index 43d4f53..6bbfc86 100644 --- a/tests/test_transforms_misc.py +++ b/tests/test_transforms_misc.py @@ -48,3 +48,13 @@ def test_typeOf(self): def test_strToLocation(self): result = self.jexl.evaluate('"-10.13,24.54"|strToLocation', {}) self.assertEqual(result, [-10.13, 24.54]) + + def test_strToLocation_five_elements(self): + result = self.jexl.evaluate('"-10.13,24.54,21,42,23"|strToLocation', {}) + self.assertEqual(result, [-10.13, 24.54, 21, 42, 23]) + + def test_strToLocation_location(self): + context = {'point': '-42.13,23.11'} + result = self.jexl.evaluate('{coordinates:(point|strToLocation), type: "Point"}', context) + self.assertEqual(result, {'coordinates': [-42.13, 23.11], 'type': 'Point'}) +