From 808a02ddf57a0da07e0183082791002f57bd5ccf Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Sun, 5 Jul 2026 17:31:12 +0800 Subject: [PATCH] feat: add find_name method to retrieve Keyword instances by name --- module/ocr/keyword.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/module/ocr/keyword.py b/module/ocr/keyword.py index 1c25175..5b8ad91 100644 --- a/module/ocr/keyword.py +++ b/module/ocr/keyword.py @@ -180,3 +180,24 @@ class Keyword: # Not found raise ScriptError(f'Cannot find a {cls.__name__} instance that matches "{name}"') + + @classmethod + def find_name(cls, name): + """ + Args: + name: Attribute name of keyword. + + Returns: + Keyword instance. + + Raises: + ScriptError: If nothing found. + """ + if isinstance(name, Keyword): + return name + for instance in cls.instances.values(): + if name == instance.name: + return instance + + # Not found + raise ScriptError(f'Cannot find a {cls.__name__} instance that matches "{name}"')