Add converter modules (JSON, YAML, TOML, CSV)
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
45
src/converters/__init__.py
Normal file
45
src/converters/__init__.py
Normal file
@@ -0,0 +1,45 @@
|
||||
"""Data format converters."""
|
||||
|
||||
from .base import BaseConverter, ConversionResult
|
||||
from .json_converter import JSONConverter
|
||||
from .yaml_converter import YAMLConverter
|
||||
from .toml_converter import TOMLConverter
|
||||
from .csv_converter import CSVConverter
|
||||
|
||||
__all__ = [
|
||||
"BaseConverter",
|
||||
"ConversionResult",
|
||||
"JSONConverter",
|
||||
"YAMLConverter",
|
||||
"TOMLConverter",
|
||||
"CSVConverter",
|
||||
"get_converter",
|
||||
]
|
||||
|
||||
SUPPORTED_FORMATS = ["json", "yaml", "toml", "csv"]
|
||||
|
||||
|
||||
def get_converter(format_name: str) -> BaseConverter:
|
||||
"""Get converter instance for specified format.
|
||||
|
||||
Args:
|
||||
format_name: Format identifier (json, yaml, toml, csv)
|
||||
|
||||
Returns:
|
||||
Converter instance for the format
|
||||
|
||||
Raises:
|
||||
ValueError: If format is not supported
|
||||
"""
|
||||
format_map = {
|
||||
"json": JSONConverter,
|
||||
"yaml": YAMLConverter,
|
||||
"toml": TOMLConverter,
|
||||
"csv": CSVConverter,
|
||||
}
|
||||
|
||||
format_lower = format_name.lower()
|
||||
if format_lower not in format_map:
|
||||
raise ValueError(f"Unsupported format: {format_name}. Supported formats: {SUPPORTED_FORMATS}")
|
||||
|
||||
return format_map[format_lower]()
|
||||
Reference in New Issue
Block a user