Add formatters module
Some checks failed
CI / build (push) Has been cancelled
CI / test (push) Has been cancelled

This commit is contained in:
2026-01-29 13:24:04 +00:00
parent d6fd00c572
commit 59d4410f4c

View File

@@ -0,0 +1,24 @@
"""Base formatter class for output formatting."""
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Any
class BaseFormatter(ABC):
"""Base class for all formatters."""
def __init__(self, output_path: Path | None = None):
self.output_path = output_path
@abstractmethod
def format(self, data: dict[str, Any]) -> str:
"""Format data and return as string."""
pass
def save(self, data: dict[str, Any]) -> None:
"""Format data and save to output path."""
if self.output_path:
self.output_path.parent.mkdir(parents=True, exist_ok=True)
content = self.format(data)
self.output_path.write_text(content, encoding="utf-8")