Slide 47
Slide 47 text
class UsageId:
usage_date: DayOfUsage
customer_id: CustomerId
@classmethod
def from_string(cls, as_text: str) -> UsageIdType:
[provided_prefix, provided_customer_id, provided_usage_date] = as_text.split(':')
if provided_prefix != 'usage':
raise SorryInvalidUsageId.because_of_unsuported_prefix()
if provided_customer_id == '':
raise SorryInvalidUsageId.because_of_missing_customer_id()
if provided_usage_date == '':
raise SorryInvalidUsageId.because_of_missing_usage_date()
return UsageId(
CustomerId.from_string(f”customer:{provided_customer_id}"),
DayOfUsage.from_string(provided_usage_date)
)