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