Coverage for collectra/text/base.py: 100.00%

11 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-13 04:26 +0000

1"""Text handling and processing classes for Collectra workflows. 

2 

3This module provides basic text data structures and utilities for handling 

4textual content within Collectra workflows. It supports text content with 

5optional path associations for file-based text processing tasks. 

6 

7Classes: 

8 Text: Basic text container with content and optional path metadata 

9""" 

10 

11from pathlib import Path 

12 

13from pydantic import BaseModel 

14 

15 

16class Text(BaseModel): 

17 """Basic text container for handling textual content in workflows. 

18 

19 Provides a simple data structure for storing text content along with 

20 optional path metadata for file-based text processing operations. 

21 

22 Attributes: 

23 content (str): The actual text content. 

24 path (Path): Optional path to the source file. 

25 """ 

26 

27 content: str 

28 path: Path | None = None 

29 

30 def __init__(self, content: str | None = None, **kwargs): 

31 """Initialize a Text instance with content. 

32 

33 Args: 

34 content (str): The text content to store. 

35 """ 

36 if content is not None: 

37 kwargs["content"] = content 

38 super().__init__(**kwargs) 

39 

40 def __str__(self): 

41 """Return the text content as a string. 

42 

43 Returns: 

44 str: The stored text content. 

45 """ 

46 return self.content