LucaCappelletti94/italian_csv_type_prediction

View on GitHub
italian_csv_type_prediction/simple_types/country_code_type.py

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
from ..datasets import load_country_codes
from .set_type_predictor import SetTypePredictor
from .simple_type import SimpleTypePredictor


class CountryCodeType(SimpleTypePredictor):

    def __init__(self):
        super().__init__()
        self._predictor = SetTypePredictor(
            load_country_codes(), normalize_values=True)

    def convert(self, candidate):
        return str(candidate).upper()

    def validate(self, candidate, **kwargs) -> bool:
        """Return boolean representing if given candidate is a valid country code."""
        return self._predictor.validate(candidate)