Minor refactoring of Transaction class.
This commit is contained in:
parent
92443d59a9
commit
d27f42644d
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from time import strftime, strptime, gmtime
|
from time import strftime, strptime, gmtime
|
||||||
from typing import Optional
|
from typing import Optional, List
|
||||||
|
|
||||||
__all__ = ["Transaction", "TYPE_INCOME", "TYPE_OUTCOME"]
|
__all__ = ["Transaction", "TYPE_INCOME", "TYPE_OUTCOME", "TIME_FORMAT"]
|
||||||
|
|
||||||
TYPE_INCOME = "in"
|
TYPE_INCOME = "in"
|
||||||
TYPE_OUTCOME = "out"
|
TYPE_OUTCOME = "out"
|
||||||
@ -12,10 +12,14 @@ TIME_FORMAT = "%Y-%m-%dT%H:%M:%S"
|
|||||||
|
|
||||||
|
|
||||||
class Transaction:
|
class Transaction:
|
||||||
"""Transaction consists of a timestamp, a direction
|
"""An object that holds a transaction.
|
||||||
and an array of coins. It doesn't depend on a currency. Only coins count is
|
|
||||||
stored."""
|
Arguments:
|
||||||
def __init__(self, coins, direction: str = TYPE_INCOME,
|
- coins -- a list of numbers represent count for each face value;
|
||||||
|
- direction -- is this income or outcome. Takes TYPE_INCOME
|
||||||
|
or TYPE_OUTCOME;
|
||||||
|
- timestamp -- date and time formated accordingly to TIME_FORMAT."""
|
||||||
|
def __init__(self, coins: List[int], direction: str = TYPE_INCOME,
|
||||||
timestamp: Optional[str] = None) -> None:
|
timestamp: Optional[str] = None) -> None:
|
||||||
self.coins = coins
|
self.coins = coins
|
||||||
if direction in [TYPE_INCOME, TYPE_OUTCOME]:
|
if direction in [TYPE_INCOME, TYPE_OUTCOME]:
|
||||||
@ -38,7 +42,7 @@ class Transaction:
|
|||||||
"""Makes a Transaction object from its string output."""
|
"""Makes a Transaction object from its string output."""
|
||||||
timestamp, direction, coins = transaction.split()
|
timestamp, direction, coins = transaction.split()
|
||||||
|
|
||||||
coins = [int(coin) for coin in coins.split(",")]
|
coins = list(map(int, coins.split(",")))
|
||||||
return Transaction(coins, direction, timestamp)
|
return Transaction(coins, direction, timestamp)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user