adding docstring to classes

This commit is contained in:
2025-11-10 19:42:41 +01:00
parent a685fe202a
commit 5fa911df00

View File

@@ -19,13 +19,17 @@ logger = logging.getLogger(__name__)
class GTINProcessor: class GTINProcessor:
"""Handles GTIN normalization and validation.""" """Handles GTIN normalization and validation."""
VALID_LENGTHS = [8, 12, 13, 14] VALID_LENGTHS = [8, 12, 13, 14] # List of valid GTIN lengths
def normalize(self, gtin_value: any) -> Optional[str]: def normalize(self, gtin_value: any) -> Optional[str]:
""" """
Normalize GTIN to proper format. Normalize GTIN to proper format.
Returns None for invalid GTINs. Args:
gtin_value (any): The GTIN value to be normalized.
Returns:
Optional[str]: The normalized GTIN string or None if the input is invalid.
""" """
if not gtin_value or pd.isna(gtin_value): if not gtin_value or pd.isna(gtin_value):
return None return None
@@ -72,7 +76,15 @@ class GTINProcessor:
return None return None
def validate(self, gtin: str) -> bool: def validate(self, gtin: str) -> bool:
"""Validate GTIN format.""" """
Validate the GTIN format.
Args:
gtin (str): The GTIN string to be validated.
Returns:
bool: True if the GTIN is valid, False otherwise.
"""
if not gtin: if not gtin:
return False return False
return len(gtin) in self.VALID_LENGTHS and gtin.isdigit() return len(gtin) in self.VALID_LENGTHS and gtin.isdigit()
@@ -97,14 +109,15 @@ class PriceProcessor:
r"([A-Z]{3})\s*([0-9.,]+)": lambda m: (m.group(2), m.group(1)), r"([A-Z]{3})\s*([0-9.,]+)": lambda m: (m.group(2), m.group(1)),
} }
def parse_price_currency( def parse_price_currency(self, price_str: any) -> Tuple[Optional[str], Optional[str]]:
self, price_str: any
) -> Tuple[Optional[str], Optional[str]]:
""" """
Parse price string into (price, currency) tuple. Parse a price string to extract the numeric value and currency.
Raises ValueError if parsing fails for non-empty input. Args:
Returns (None, None) for empty/null input. price_str (any): The price string to be parsed.
Returns:
Tuple[Optional[str], Optional[str]]: A tuple containing the parsed price and currency, or None if parsing fails.
""" """
if not price_str or pd.isna(price_str): if not price_str or pd.isna(price_str):
return None, None return None, None