Source code for yieldplotlib.core.node
"""The abstract base class for all nodes (files and directories)."""
from abc import ABC, abstractmethod
from pathlib import Path
[docs]
class Node(ABC):
"""Abstract base class for all nodes (files and directories)."""
def __init__(self, file_path: Path):
"""Initialize the node with a reference to the data."""
self.data = None
self.file_path = file_path
self.file_name = file_path.name
self.is_input = False
[docs]
@abstractmethod
def load(self):
"""Load the file data or trigger recursive loading for directories."""
pass
[docs]
@abstractmethod
def get(self, key: str, **kwargs):
"""Abstract method to search for data associated with a key."""
pass
[docs]
def has_key(self, key: str) -> bool:
"""Abstract method to determine if the node contains the given key."""
return False
[docs]
def __repr__(self):
"""Default representation for a DataNode."""
return f"<{self.__class__.__name__}: {self.file_name}>"
[docs]
def display_tree(self, level=0, max_children=5, prefix=""):
"""Default display method for a DataNode."""
return f"{prefix}{self.__repr__()}\n"