"""Classes for everything
Todo:
Add ``__str__`` and ``__repr__`` methods for each class (:issue:`1`)
"""
from datetime import date
from typing import Optional, Union
[docs]class Company:
"""A company/business
.. versionadded:: 0.1.0
Args:
name (str): The company's name
"""
def __init__(self, name: str):
self.name = name
def __eq__(self, other):
if isinstance(other, type(self.name)):
return self.name == other
return self.name == other.name
[docs]class Occupation:
"""An occupation
.. versionadded:: 0.1.0
Args:
title (str): The job title
company (:class:`~everything.Company` or str, optional): The company
Note:
If ``company`` is not given as a :class:`~everything.Company` object, it will be converted to one.
Keyword Args:
department (str, optional): The department
"""
def __init__(
self,
title: str,
company: Optional[Union[Company, str]] = None,
*,
department: Optional[str] = None
):
self.title = title
if isinstance(company, Company):
self.company = company
else:
self.company = Company(company)
self.department = department
def __eq__(self, other):
return (
self.title == other.title
and self.company == other.company
and self.department == other.department
)
[docs]class Person:
"""A person
.. versionadded:: 0.1.0
Args:
name (str): The person's name
Keyword Args:
birthday (datetime.date, optional): The person's date of birth
occupation (:class:`~everything.Occupation`, optional): The person's occupation
Attributes:
company (:class:`~everything.Company`, optional): The person's company (based on occupation)
department (str, optional): The person's company (based on occupation)
Todo:
When a person's occupation is changed, their company and department should too (:issue:`2`)
"""
def __init__(
self,
name: str,
*,
birthday: Optional[date] = None,
occupation: Optional[Occupation] = None
):
self.name = name
self.birthday = birthday
self.occupation = occupation
if occupation:
self.company = occupation.company
self.department = occupation.department
else:
self.company = None
self.department = None
def __eq__(self, other):
return (
self.name == other.name
and self.birthday == other.birthday
and self.occupation == other.occupation
)