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