Passed
Push — master ( ea2adf...c3c03e )
by Steffen
02:29
created

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

Complexity

Conditions 1

Size

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