Source code for tdw_catalog.metadata.currency

import json
from typing import Optional

from tdw_catalog.utils import MetadataFieldType, CurrencyFieldValue
import tdw_catalog.metadata.field as field


[docs]class Field(field.MetadataField[CurrencyFieldValue]): """ A field for currency values Attributes ---------- currency : Optional[str] An optional three character string representation for this currency type (e.g. USD) amount: Optional[float] An optional fractional amount of currency for this currency field """ def __init__(self, key: str, currency: Optional[str], amount: Optional[float]) -> None: value = CurrencyFieldValue(value=amount, currency=currency) super().__init__(key, value) value: Optional[CurrencyFieldValue] def serialize(self) -> dict: res = super().serialize() res["value"] = json.dumps({ "value": self.value.value, "currency": self.value.currency }) res["field_type"] = MetadataFieldType.FT_CURRENCY return res