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

kuon.watcher.currency   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 0
loc 44
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A Currency.__init__() 0 10 1
A Currency.__repr__() 0 6 1
A Currency.amount() 0 7 1
A Currency.human_readable() 0 10 2
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