Total Complexity | 5 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | #!/usr/bin/python |
||
2 | # -*- coding: utf-8 -*- |
||
3 | |||
4 | |||
5 | 1 | class Currency: |
|
6 | """Class to parse currency amount in a readable format""" |
||
7 | |||
8 | 1 | def __init__(self, amount: int, currency_sign: str = "$", currency_sign_start: bool = True) -> None: |
|
9 | """Initializing function |
||
10 | |||
11 | :type amount: int |
||
12 | :type currency_sign: str |
||
13 | :type currency_sign_start: bool |
||
14 | """ |
||
15 | 1 | self._amount = amount |
|
16 | 1 | self._currency_sign = currency_sign |
|
17 | 1 | self._currency_sign_start = currency_sign_start |
|
18 | |||
19 | def __repr__(self) -> str: |
||
20 | """Return the readable format |
||
21 | |||
22 | :return: |
||
23 | """ |
||
24 | return self.human_readable |
||
25 | |||
26 | 1 | @property |
|
27 | 1 | def human_readable(self) -> str: |
|
28 | """Return the amount in a readable format like $15.00 instead of 1500 |
||
29 | |||
30 | :return: |
||
31 | """ |
||
32 | 1 | if self._currency_sign_start: |
|
33 | 1 | return "{0:s}{1:.2f}".format(self._currency_sign, self._amount / 100) |
|
34 | else: |
||
35 | 1 | return "{1:.2f}{0:s}".format(self._currency_sign, self._amount / 100) |
|
36 | |||
37 | 1 | @property |
|
38 | 1 | def amount(self) -> int: |
|
39 | """Get the raw amount |
||
40 | |||
41 | :return: |
||
42 | """ |
||
43 | return self._amount |
||
44 |