yagwr.rules: Rules container

class yagwr.rules.Rule(condition, action)

Bases: object

This class reprents a rule. A rule is the cobination of a condition and action. If the condition matches, the action can be executed.

Parameters
  • condition (checker.Node) – A Node object that holds the condition

  • action (any) – the action. This object just stores the action, it doesn’t manipulate it. Hence you can set any object you like.

matches(obj)

Return whether the condition matches the object

Parameters

obj (dict) – The object with which the condition is checked. See checker for more information about the shape of the object.

Returns

True if the condition matches, False otherwise

Return type

bool

classmethod from_dict(obj)

Generates a new Rule object from a dictionary.

The dictionary must have two key:

  • condition: see The condition dictionary for more information

  • action: an object (usually string) with the action to be taken

    when the condition matches

Returns

A new rule

Return type

Rule

Raises

checker.InvalidExpression – when parsing the condition fails