Coverage for domain / outputs / plain_text_handler.py: 100.00%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-07 00:07 +0000

1"""Plain text output handler.""" 

2from pathlib import Path 

3from typing import List 

4from domain.core.output_handler import OutputHandler 

5 

6 

7class PlainTextHandler(OutputHandler): 

8 """Handler for saving content as plain text files.""" 

9 

10 def save(self, content: str, destination: Path) -> int: 

11 output_path = destination.with_suffix(".txt") 

12 output_path.write_text(content, encoding="utf-8") 

13 return output_path.stat().st_size 

14 

15 def save_multiple(self, contents: List[str], destination: Path, source_name: str) -> int: 

16 """Save each page/chapter as a separate numbered text file.""" 

17 stem = destination.stem 

18 parent = destination.parent 

19 total_size = 0 

20 

21 for idx, content in enumerate(contents, start=1): 

22 output_path = parent / f"{stem}_page_{idx}.txt" 

23 output_path.write_text(content, encoding="utf-8") 

24 total_size += output_path.stat().st_size 

25 

26 return total_size