Coverage for src/platform_adapter/base_adapter.py: 91%

1# Base Adapter

2 from __future__ import annotations

3

4 from abc import ABC, abstractmethod

5 from dataclasses import dataclass

6 from typing import Any

7

8

9@dataclass

10 class PlatformContent:

11 title: str | None

12 body: str

13 metadata: dict[str, Any]

14

15

16 class BaseAdapter(ABC):

17 def __init__(self, config: dict[str, Any] | None = None):

18 self.config = config or {}

19

20 @abstractmethod

21 def get_max_length(self) -> int:

22 pass

23

24 @abstractmethod

25 def format_content(self, content: str, **kwargs: Any) -> PlatformContent:

26 pass

27

28 def truncate_content(self, content: str, max_length: int | None = None) -> str:

29 max_len = max_length or self.get_max_length()

30 if len(content) <= max_len:

31 return content

32 return content[: max_len - 3] + "..."