diff --git a/TUTORIAL.md b/TUTORIAL.md index f1852898..19b2fc71 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -96,8 +96,9 @@ Optional properties: - `type` (if present must be one of: `int`, `float`, `date`) -results in parsing every matched value to a specified type -- `group` (if present must be `sum`) - results in grouping all matched - values using specified method +- `group` (if present must be one of: `sum`, `min`, `max`, `first`, + `last`) - specifies grouping function (defines what value to return in + case of multiple matches) Example for `regex`: diff --git a/src/invoice2data/extract/parsers/regex.py b/src/invoice2data/extract/parsers/regex.py index 2909d3ed..85ba3ccd 100644 --- a/src/invoice2data/extract/parsers/regex.py +++ b/src/invoice2data/extract/parsers/regex.py @@ -49,6 +49,14 @@ def parse(template, field, settings, content, legacy=False): if "group" in settings: if settings["group"] == "sum": result = sum(result) + elif settings["group"] == "min": + result = min(result) + elif settings["group"] == "max": + result = max(result) + elif settings["group"] == "first": + result = result[0] + elif settings["group"] == "last": + result = result[-1] else: logger.warning("Unsupported grouping method: " + settings["group"]) return None