refactor: move matching logic in Code class
This commit is contained in:
10
__init__.py
10
__init__.py
@@ -16,7 +16,10 @@ class Code:
|
||||
self.code = code
|
||||
self.name = name
|
||||
self.description = description
|
||||
self.match = f"{code} {name}"
|
||||
self.match = f"{code} {name}".casefold()
|
||||
|
||||
def is_match(self, query: str) -> bool:
|
||||
return query.casefold() in self.match
|
||||
|
||||
codes = [
|
||||
Code(100, "Continue", "The client should continue the request."),
|
||||
@@ -84,10 +87,11 @@ codes = [
|
||||
def build_query_items(query):
|
||||
results = []
|
||||
for code in codes:
|
||||
if query.string.casefold() in code.match.casefold():
|
||||
if code.is_match(query.string):
|
||||
results.append(
|
||||
# https://albertlauncher.github.io/reference/classalbert_1_1util_1_1StandardItem.html
|
||||
albert.StandardItem(
|
||||
id='uuid',
|
||||
id=str(code.code),
|
||||
text=f"{code.code} {code.name}",
|
||||
subtext=code.description,
|
||||
actions=[]
|
||||
|
||||
Reference in New Issue
Block a user