diff --git a/exercise-1.py b/exercise-1.py index 1323c1b..651acb6 100644 --- a/exercise-1.py +++ b/exercise-1.py @@ -15,18 +15,24 @@ import unittest -EMAIL_PATTERN = re.compile(r'^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$') +class EMail: + EMAIL_PATTERN = re.compile(r'^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$') + def __init__(self, email): + if self.EMAIL_PATTERN.match(email) is None: + raise ValueError('Invalid email') + else: + self.email = email + + def __str__(self): + return self.email class Person: def __init__(self, first_name, last_name, email): assert isinstance(first_name, str) assert isinstance(last_name, str) assert isinstance(email, str) - - self.first_name = first_name + + self.first_name = first_name self.last_name = last_name - if EMAIL_PATTERN.match(email) is None: - raise ValueError('Invalid email') - else: - self.email = email + self.email = EMail(email)