Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more operators to rule engine #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions business_rules/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def ends_with(self, other_string):
def contains(self, other_string):
return other_string in self.value

@type_operator(FIELD_TEXT, label="Contains (case insensitive)")
def contains_case_insensitive(self, other_string):
return other_string.lower() in self.value.lower()

@type_operator(FIELD_TEXT)
def matches_regex(self, regex):
return re.search(regex, self.value)
Expand All @@ -95,6 +99,10 @@ def matches_regex(self, regex):
def non_empty(self):
return bool(self.value)

@type_operator(FIELD_NO_INPUT)
def is_empty(self):
return self.value is None or self.value.strip() == ""


@export_type
class NumericType(BaseType):
Expand All @@ -119,6 +127,10 @@ def _assert_valid_value_and_cast(value):
def equal_to(self, other_numeric):
return abs(self.value - other_numeric) <= self.EPSILON

@type_operator(FIELD_NUMERIC)
def not_equal_to(self, other_numeric):
return abs(self.value - other_numeric) > self.EPSILON

@type_operator(FIELD_NUMERIC)
def greater_than(self, other_numeric):
return (self.value - other_numeric) > self.EPSILON
Expand Down