Skip to content

Commit 4f612c7

Browse files
committed
#69 - Overloading the method 'parse_message' for BoolEntityField class to provide a special behavior when parsing messages
1 parent 5a6f140 commit 4f612c7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pyttman/core/entity_parsing/fields.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
from abc import ABC
33
from typing import Any, Sequence, Type
44

5+
from pyttman.core.entity_parsing.entity import Entity
6+
7+
from pyttman.core.containers import MessageMixin, Message
8+
59
from pyttman.core.entity_parsing.identifiers import IntegerIdentifier, \
610
Identifier
711
from pyttman.core.entity_parsing.parsers import EntityFieldValueParser
@@ -155,6 +159,15 @@ def __init__(self, *args,
155159
**kwargs):
156160
super().__init__(*args, valid_strings=message_contains, **kwargs)
157161

162+
def parse_message(self,
163+
message: MessageMixin,
164+
original_message_content: tuple[str],
165+
memoization: dict = None) -> None:
166+
original_content = Message(original_message_content).lowered_content()
167+
self.value = Entity(value=self.default, is_fallback_default=True)
168+
if set(self.valid_strings).intersection(original_content):
169+
self.value = Entity(value=True)
170+
158171

159172
if __name__ != "__main__":
160173
StringEntityField = TextEntityField

0 commit comments

Comments
 (0)