diff --git a/app/utils/data_processing.py b/app/utils/data_processing.py index a6381973..fe44665b 100644 --- a/app/utils/data_processing.py +++ b/app/utils/data_processing.py @@ -19,13 +19,17 @@ logger = logging.getLogger(__name__) class GTINProcessor: """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]: """ 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): return None @@ -72,7 +76,15 @@ class GTINProcessor: return None 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: return False 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)), } - def parse_price_currency( - self, price_str: any - ) -> Tuple[Optional[str], Optional[str]]: + def parse_price_currency(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. - Returns (None, None) for empty/null input. + Args: + 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): return None, None