Passed
Push — master ( 8237dc...91831d )
by Steffen
01:46
created

tw_serverinfo.models.player.Player.name()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 2
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
#!/usr/local/bin/python
2
# coding: utf-8
3 1
from pycountry import countries
4
5 1
from tw_serverinfo.utility.countries import custom_countries
6
7
8 1
class Player(object):
9
    """Player Model Template, containing properties for all possible attributes of players"""
10 1
    _name = ''
11 1
    _clan = ''
12 1
    _country_index = '-1'
13 1
    _score = 0
14 1
    _ingame = False
15
16 1
    def __init__(self, name: str, clan: str = '', country: int = -1, score: int = 0, ingame: bool = False) -> None:
17
        """Initializing function
18
19
        :type name: str
20
        :type clan: str
21
        :type country: int
22
        :type score: int
23
        :type ingame: bool
24
        """
25 1
        self.name = name
26 1
        self.clan = clan
27 1
        if country == -1:
28 1
            self._country_index = str(country)
29
        else:
30 1
            self.country = str(country)
31 1
        self.score = score
32 1
        self.ingame = ingame
33
34
    def __repr__(self) -> str:
35
        """Reprint function, displays player details instead of instance information
36
37
        :return:
38
        """
39
        return 'Player(name={name:s}, clan={clan:s}, country={country:s}, country_index={country_index:d}' \
40
               'score={score:d}, ingame={ingame!r})'.format(name=self.name, clan=self.clan, country=self.country,
41
                                                            country_index=self.country_index, score=self.score,
42
                                                            ingame=self.ingame)
43
44 1
    def __eq__(self, other) -> bool:
45
        """Check for equality of objects
46
47
        :type other: Player
48
        :return:
49
        """
50 1
        return self.name == other.name and self.clan == other.clan
51
52 1
    @property
53 1
    def name(self) -> str:
54 1
        return self._name
55
56 1
    @name.setter
57 1
    def name(self, name: str) -> None:
58 1
        self._name = name
59
60 1
    @property
61 1
    def clan(self) -> str:
62 1
        return self._clan
63
64 1
    @clan.setter
65 1
    def clan(self, clan: str) -> None:
66 1
        self._clan = clan
67
68 1
    @property
69 1
    def country(self) -> str:
70
        if self._country_index in custom_countries:
71
            return custom_countries[self._country_index]['name']
72
        else:
73
            return countries.get(numeric=str(self._country_index)).name
74
75 1
    @country.setter
76 1
    def country(self, country: str) -> None:
77 1
        if country in custom_countries:
78
            self._country_index = country
79
        else:
80 1
            zfilled_country = country.zfill(3)
81
            # only allow to set indexes which are known
82 1
            if countries.lookup(zfilled_country):
83 1
                self._country_index = countries.lookup(zfilled_country).numeric
84
85 1
    @property
86 1
    def country_code(self) -> str:
87
        if self._country_index in custom_countries:
88
            return custom_countries[self._country_index]['code']
89
        else:
90
            return countries.get(numeric=str(self._country_index)).alpha_2
91
92 1
    @property
93 1
    def country_index(self) -> int:
94
        return int(self._country_index)
95
96 1
    @property
97 1
    def score(self) -> int:
98
        return self._score
99
100 1
    @score.setter
101 1
    def score(self, score: int) -> None:
102 1
        self._score = score
103
104 1
    @property
105 1
    def ingame(self) -> bool:
106
        return self._ingame
107
108 1
    @ingame.setter
109 1
    def ingame(self, ingame: bool) -> None:
110
        self._ingame = ingame
111