<filename>bot_scheduler/actions.py<gh_stars>0
from typing import Callable


class Action:
    """Encapsulates the calling of a callback with an object."""

    def __init__(self, actor: Callable):
        """Initialise the Action with a callback.

        Args:
            actor: Takes one argument and acts on it.
        """
        if not callable(actor):
            raise ValueError('The interactor argument should be callable.')
        self._interactor = actor

    def act(self, obj: object):
        self._interactor(obj)


class EvaluatingAction(Action):
    """Encapsulations the conditional calling of a callback with an object."""

    def __init__(self, actor: Callable, evaluator: Callable):
        """Initialise the EvaluatingAction with two callbacks.

        Args:
            actor: Takes one argument and acts on it.
            evaluator: Takes one argument and determines whether to act on it.
        """
        if not callable(evaluator):
            raise ValueError('The evaluator argument should be callable.')

        self._evaluator = evaluator
        super().__init__(actor)

    def act(self, obj: object):
        if self._evaluator(obj):
            super().act(obj)

<filename>bot_scheduler/actions.py<gh_stars>0
from typing import Callable


class Action:
    """Encapsulates the calling of a callback with an object."""

    def __init__(self, actor: Callable):
        """Initialise the Action with a callback.

        Args:
            actor: Takes one argument and acts on it.
        """
        if not callable(actor):
            raise ValueError('The interactor argument should be callable.')
        self._interactor = actor

    def act(self, obj: object):
        self._interactor(obj)


class EvaluatingAction(Action):
    """Encapsulations the conditional calling of a callback with an object."""

    def __init__(self, actor: Callable, evaluator: Callable):
        """Initialise the EvaluatingAction with two callbacks.

        Args:
            actor: Takes one argument and acts on it.
            evaluator: Takes one argument and determines whether to act on it.
        """
        if not callable(evaluator):
            raise ValueError('The evaluator argument should be callable.')

        self._evaluator = evaluator
        super().__init__(actor)

    def act(self, obj: object):
        if self._evaluator(obj):
            super().act(obj)

Encapsulates the calling of a callback with an object. Initialise the Action with a callback.          Args:             actor: Takes one argument and acts on it. Encapsulations the conditional calling of a callback with an object. Initialise the EvaluatingAction with two callbacks.          Args:             actor: Takes one argument and acts on it.             evaluator: Takes one argument and determines whether to act on it.