From 99b903b69ffa0f3afe8d2a31bf23e399a45af609 Mon Sep 17 00:00:00 2001 From: Lyndsy Simon Date: Wed, 21 Nov 2018 13:02:25 -0600 Subject: [PATCH] Refactor formatters as a module --- columnist/formatters/__init__.py | 1 + columnist/formatters/base.py | 18 ++++++++++++++++++ columnist/{formatters.py => formatters/csv.py} | 18 +----------------- 3 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 columnist/formatters/__init__.py create mode 100644 columnist/formatters/base.py rename columnist/{formatters.py => formatters/csv.py} (58%) diff --git a/columnist/formatters/__init__.py b/columnist/formatters/__init__.py new file mode 100644 index 0000000..0ab21af --- /dev/null +++ b/columnist/formatters/__init__.py @@ -0,0 +1 @@ +from .csv import CSVFormatter # noqa: F401 diff --git a/columnist/formatters/base.py b/columnist/formatters/base.py new file mode 100644 index 0000000..5805d8a --- /dev/null +++ b/columnist/formatters/base.py @@ -0,0 +1,18 @@ +import abc + +import columnist + + +class Formatter(metaclass=abc.ABCMeta): + def __init__(self, report: columnist.Report): + self.report = report + + @abc.abstractmethod + def to_file(self, destination, **options) -> None: + """Write the formatted report to a file""" + pass + + @abc.abstractmethod + def to_string(self, **options) -> str: + """Return the formatted report as a string""" + pass diff --git a/columnist/formatters.py b/columnist/formatters/csv.py similarity index 58% rename from columnist/formatters.py rename to columnist/formatters/csv.py index f645b42..5a8939c 100644 --- a/columnist/formatters.py +++ b/columnist/formatters/csv.py @@ -1,23 +1,7 @@ -import abc import csv import io -import columnist - - -class Formatter(metaclass=abc.ABCMeta): - def __init__(self, report: columnist.Report): - self.report = report - - @abc.abstractmethod - def to_file(self, destination, **options) -> None: - """Write the formatted report to a file""" - pass - - @abc.abstractmethod - def to_string(self, **options) -> str: - """Return the formatted report as a string""" - pass +from .base import Formatter class CSVFormatter(Formatter): -- 2.45.2