Skip to content

Commit

Permalink
fix: fixes README
Browse files Browse the repository at this point in the history
  • Loading branch information
nf1s committed Feb 2, 2024
1 parent eef2018 commit 577186c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ from rules_engine import Rule, RulesEngine, when, then

name = "fyndiq"

RulesEngine(Rule(when(name == "fyndiq"),then(True))).run(name)
RulesEngine(Rule(when(name == "fyndiq"),then(True), 'it is fyndiq')).run(name)

>>> True
>>> Result(value=True, message='it is fyndiq')
```

## When
Expand All @@ -42,12 +42,12 @@ let's check if a value is `None` and raise an exception.
from rules_engine import Rule, RulesEngine, when
obj = None

def cannot_be_none_error():
def no_a_string(obj):
return "not a string error"

RulesEngine(Rule(when(obj is None), cannot_be_none_error)).run(obj)

>>> 'not a string error'
>>> Result(value='not a string error', message=None)
```

## Then
Expand All @@ -61,7 +61,7 @@ obj = None

RulesEngine(Rule(when(obj is None), then('not a string error'))).run(obj)

>>> 'not a string error'
>>> Result(value='not a string error', message=None)
```

## Not
Expand All @@ -80,9 +80,9 @@ def is_missing(obj):

obj="Hello"

RulesEngine(Rule(not_(is_missing), then(True))).run(obj)
RulesEngine(Rule(not_(is_missing), then(True)), 'object is missing').run(obj)

>>> True
>>> Result(value=True, message='object is missing')
```

## All
Expand All @@ -107,7 +107,7 @@ obj = [1,2]

RulesEngine(Rule(all_(not_(is_missing), is_a_list), then(True))).run(obj)

>>> True
>>> Result(value=True, message=None)
```

## Any
Expand All @@ -130,9 +130,9 @@ def is_a_list(obj):

obj = "Hello"

RulesEngine(Rule(any_(is_a_str, is_a_list), then(True))).run(obj)
RulesEngine(Rule(any_(is_a_str, is_a_list), then(True), "it is a string or a list")).run(obj)

>>> True
>>> Result(value=True, message="it is a string or a list")
```

## Run/RunAll
Expand Down Expand Up @@ -160,7 +160,7 @@ RulesEngine(
Rule(is_string, then("string")),
).run(value)

>>> "integer"
>>> Result(value='integer', message=None)
```

Since the first rule satisfies the conditions the rules engine will go no further
Expand Down Expand Up @@ -191,7 +191,7 @@ RulesEngine(
Rule(is_gr_3_chars, then("greater than 3 charcters")),
).run_all(value)

>>> ["string", "greater than 3 charcters"]
>>>[Result(value='string', message=None),Result(value='greater than 3 charcters', message=None)]

```

Expand Down

0 comments on commit 577186c

Please sign in to comment.