Module chillow.service.data_writer

Expand source code
import json

from abc import ABCMeta, abstractmethod
from chillow.model.action import Action


class DataWriter(metaclass=ABCMeta):
    """Converts an object to a string."""

    @abstractmethod
    def write(self, action: Action) -> str:
        """Converts an action to a string.

        Args:
            action: The action to be converted.

        Returns:
            The action as a string.
        """
        pass


class JSONDataWriter(DataWriter):
    """Converts an object to a JSON string."""

    def write(self, action: Action) -> str:
        """See base class."""
        return json.dumps({"action": action.name})

Classes

class DataWriter

Converts an object to a string.

Expand source code
class DataWriter(metaclass=ABCMeta):
    """Converts an object to a string."""

    @abstractmethod
    def write(self, action: Action) -> str:
        """Converts an action to a string.

        Args:
            action: The action to be converted.

        Returns:
            The action as a string.
        """
        pass

Subclasses

Methods

def write(self, action: Action) ‑> str

Converts an action to a string.

Args

action
The action to be converted.

Returns

The action as a string.

Expand source code
@abstractmethod
def write(self, action: Action) -> str:
    """Converts an action to a string.

    Args:
        action: The action to be converted.

    Returns:
        The action as a string.
    """
    pass
class JSONDataWriter

Converts an object to a JSON string.

Expand source code
class JSONDataWriter(DataWriter):
    """Converts an object to a JSON string."""

    def write(self, action: Action) -> str:
        """See base class."""
        return json.dumps({"action": action.name})

Ancestors

Methods

def write(self, action: Action) ‑> str

See base class.

Expand source code
def write(self, action: Action) -> str:
    """See base class."""
    return json.dumps({"action": action.name})