diff --git a/src/predicates.py b/src/predicates.py index 8f3108e..bd05c79 100644 --- a/src/predicates.py +++ b/src/predicates.py @@ -16,4 +16,5 @@ PREDICATE_METHOD_MAP = { "is like": PropertyRules.is_parameter_value_like.__name__, "identical to": PropertyRules.is_identical_value.__name__, "not equal": PropertyRules.is_not_equal_value.__name__, + "contains": PropertyRules.is_parameter_value_containing.__name__, } diff --git a/src/rules.py b/src/rules.py index d6ca8ef..ca21351 100644 --- a/src/rules.py +++ b/src/rules.py @@ -60,6 +60,31 @@ class Rules: class PropertyRules: """A collection of rules for processing parameters in Speckle objects.""" + @staticmethod + def is_parameter_value_contains(speckle_object: Base, parameter_name: str, substring: str) -> bool: + """Checks if parameter value contains the given substring. + + Args: + speckle_object: The Speckle object to check + parameter_name: Name of the parameter to check + substring: The substring to look for + + Returns: + bool: True if the parameter value contains the substring + """ + parameter_value = PropertyRules.get_parameter_value(speckle_object, parameter_name) + if parameter_value is None: + return False + + # Convert both to strings for comparison + try: + parameter_str = str(parameter_value).lower() + substring_str = str(substring).lower() + return substring_str in parameter_str + except (TypeError, ValueError) as e: + print(f"Error in is_parameter_value_contains: {e}") + return False + @staticmethod def normalize_path(path: str) -> str: """Remove technical path prefixes like 'properties' and 'parameters'."""