Skip to content

Commit

Permalink
refactor(constants/enums): DRY shared transaction patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-awd committed Oct 31, 2023
1 parent 02d161d commit 855665d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions monopoly/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,27 @@ class StatementFields(AutoEnum):
class SharedPatterns(StrEnum):
AMOUNT = r"(?P<amount>[\d.,]+)$"
DESCRIPTION = r"(?P<description>.*?)\s+"
TRANSACTION_DATE_ABBREVIATED_ALL_CAPS = r"(?P<transaction_date>\d{2}\s[A-Z]{3})\s+"
TRANSACTION_DATE_ABBREVIATED_PROPER_CASE = (
r"(?P<transaction_date>\d{2}\s[A-Z]{1}[a-z]{2})\s+"
)
POSTING_DATE_ABBREVIATED_PROPER = r"(?P<posting_date>\d{2}\s[A-Z]{1}[a-z]{2})\s+"


class TransactionPatterns(StrEnum):
DBS = (
r"^(?P<transaction_date>\d{2}\s[A-Z]{3})\s+"
SharedPatterns.TRANSACTION_DATE_ABBREVIATED_ALL_CAPS
+ SharedPatterns.DESCRIPTION
+ SharedPatterns.AMOUNT
)
CITIBANK = (
r"^(?P<transaction_date>\b\d{2}\s\w{3}\b)\s+"
SharedPatterns.TRANSACTION_DATE_ABBREVIATED_ALL_CAPS
+ SharedPatterns.DESCRIPTION
+ SharedPatterns.AMOUNT
)
HSBC = (
r"^(?P<posting_date>\d{2}\s[A-Z]{1}[a-z]{2})\s+"
r"(?P<transaction_date>\d{2}\s[A-Z]{1}[a-z]{2})\s+"
SharedPatterns.POSTING_DATE_ABBREVIATED_PROPER
+ SharedPatterns.TRANSACTION_DATE_ABBREVIATED_PROPER_CASE
+ SharedPatterns.DESCRIPTION
+ SharedPatterns.AMOUNT
)
Expand All @@ -61,8 +66,8 @@ class TransactionPatterns(StrEnum):
+ SharedPatterns.AMOUNT
)
STANDARD_CHARTERED = (
r"^(?P<posting_date>\d{2}\s[A-Z]{1}[a-z]{2})\s+"
r"(?P<transaction_date>\d{2}\s[A-Z]{1}[a-z]{2})\s+"
SharedPatterns.POSTING_DATE_ABBREVIATED_PROPER
+ SharedPatterns.TRANSACTION_DATE_ABBREVIATED_PROPER_CASE
+ SharedPatterns.DESCRIPTION
+ r"(?P<transaction_ref>Transaction\sRef\s\d+)\s+"
+ SharedPatterns.AMOUNT
Expand Down

0 comments on commit 855665d

Please sign in to comment.