Addressed comments in the PR.

This commit is contained in:
julio.oliveira 2024-01-26 16:38:24 -03:00
parent b14c447fcf
commit 8998a34b02

View File

@ -134,15 +134,11 @@ class ConditionSet:
if type(ruleset) is not dict: if type(ruleset) is not dict:
raise ValueError(f"Ruleset must be a dictionary, not {type(ruleset)}.") raise ValueError(f"Ruleset must be a dictionary, not {type(ruleset)}.")
self.logic = None
# If logic type use it, else return the ruleset
if len(ruleset) == 1: if len(ruleset) == 1:
logic = list(ruleset.keys())[0] self.logic = (list(ruleset.keys())[0]).lower()
if logic not in (AND, OR): if self.logic not in (AND, OR):
raise ValueError( raise ValueError(
f"Invalid logic type: {logic} (must be '{AND}' or '{OR}'). Please check documentation.") f"Invalid logic type: {self.logic} (must be '{AND}' or '{OR}'). Please check documentation.")
self.logic = logic.lower()
# Compile the set of Conditions # Compile the set of Conditions
self.conditions = [ self.conditions = [
@ -151,6 +147,7 @@ class ConditionSet:
] ]
else: else:
try: try:
self.logic = None
self.conditions = [Condition(**ruleset)] self.conditions = [Condition(**ruleset)]
except TypeError: except TypeError:
raise ValueError(f"Incorrect key(s) informed. Please check documentation.") raise ValueError(f"Incorrect key(s) informed. Please check documentation.")