kuon.watcher.currency   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 0
loc 44
ccs 13
cts 13
cp 1
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 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