Completed
Push — master ( 72b331...d4b7d2 )
by Steffen
02:14
created

kuon.watcher.currency.Currency.__repr__()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nop 1
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