fledermaus/table_handler/commands/regex_group_valuebased_choose.py

22 lines
576 B
Python

import regex
class RegexGroupValuebasedChoose:
def __init__(self, match: str, highest: bool):
self.match = match
self.highest = highest
def execute_on_cell(self, entry):
matches = regex.match(self.match, entry.value)
if not matches:
return None
groups = matches.groups(default=[])
values = sorted(map(lambda x: int(x), groups))
if not len(values):
return None
if self.highest:
return str(values[-1])
else:
return str(values[0])