Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol to Currency Code #37

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion currency_symbols/currency_symbols.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from typing import Optional
from typing import Optional, List, Any
from ._constants import CURRENCY_SYMBOLS_MAP


Expand All @@ -21,3 +21,20 @@ def get_symbol(currency: str) -> Optional[str]:
"""

return CURRENCY_SYMBOLS_MAP.get(currency.upper(), None)

@staticmethod
def get_currency_code(currency_symbol: str) -> list[Any]:
"""Converts provided currency symbol into currency code.

Parameters
----------
Currency symbol : str
ISO 4217 - Currency Codes

Returns
-------
Optional[str]
Currency, None if not exists.
"""

return [currency_code for currency_code, symbol in CURRENCY_SYMBOLS_MAP.items() if symbol == currency_symbol]
26 changes: 26 additions & 0 deletions currency_symbols/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,29 @@ def test_currency_symbols(self) -> None:
"₸",
"Should return KZT symbol"
)

def test_currency_code(self) -> None:
self.assertEqual(
CurrencySymbols.get_currency_code("₹"),
['INR'],
"Return a list containing INR"
)

self.assertEqual(
CurrencySymbols.get_currency_code("$"),
['ARS', 'AUD', 'BBD', 'BMD', 'BND', 'BSD', 'CAD', 'CLP', 'COP', 'CUC', 'CVE', 'FJD', 'GYD', 'HKD', 'KYD',
'LRD', 'MXN', 'NAD', 'NZD', 'SBD', 'SGD', 'SRD', 'SVC', 'TVD', 'USD', 'XCD'],
"Return list containing ARS, AUD, BBD, BMD, BND, BSD, CAD, CLP, COP, CUC, CVE, FJD, GYD, HKD, KYD, LRD, MXN, NAD, NZD, SBD, SGD, SRD, SVC, TVD, USD, XCD"
)

self.assertEqual(
CurrencySymbols.get_currency_code("£"),
['EGP', 'FKP', 'GBP', 'GGP', 'GIP', 'IMP', 'JEP', 'LBP', 'SHP', 'SSP', 'SYP'],
"Return a list containing EGP, FKP, GBP, GGP, GIP, IMP, JEP, LBP, SHP, SSP, SYP"
)

self.assertEqual(
CurrencySymbols.get_currency_code("¥"),
['CNY', 'JPY'],
"Return a list containing CNY, JPY"
)