From 379124065f7c7759c06ef31ba139b46b99bbd5b3 Mon Sep 17 00:00:00 2001 From: Harrison Cook Date: Tue, 4 Mar 2025 16:39:26 +0000 Subject: [PATCH] Add Wildcard --- src/python/qubed/value_types.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/python/qubed/value_types.py b/src/python/qubed/value_types.py index 33c46e6..76d4794 100644 --- a/src/python/qubed/value_types.py +++ b/src/python/qubed/value_types.py @@ -95,6 +95,37 @@ class DateEnum(QEnum): return "/".join(map(fmt, sorted(self.values))) +@dataclass(frozen=True) +class WildCard(ValueGroup): + def summary(self) -> str: + "Provide a string summary of the value group." + return "Includes all options" + + def __len__(self) -> int: + "Return how many values this group contains." + return -1 + + def __contains__(self, value: Any) -> bool: + "Given a value, coerce to the value type and determine if it is in the value group." + return True + + @abstractmethod + def __iter__(self) -> Iterable[Any]: + "Iterate over the values in the group." + pass + + @classmethod + def from_strings(cls, values: Iterable[str]) -> list["ValueGroup"]: + "Given a list of strings, return a one or more ValueGroups of this type." + return [cls()] + + def min(self): + "Return the minimum value in the group." + return -1 + + def to_json(self) -> dict: + "Return a JSON serializable representation of the value group." + return dataclasses.asdict(self) @dataclass(frozen=True) class Range(ValueGroup, ABC):