Completed
Push — master ( 24fe2a...025da3 )
by Oleksandr
01:08
created

il2fb.parsers.mission.to_belligerent()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
cc 1
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
1
# -*- coding: utf-8 -*-
2
3 1
from il2fb.commons import Skills, UnitTypes
4 1
from il2fb.commons.organization import AirForces, Belligerents
5
6 1
from .constants import NULL
7
8
9 1
def to_bool(value):
10
    """
11
    Converts a string representation of a number into boolean.
12
13
    :param str value: a string representation of a number to convert
14
15
    :returns: `False` if `value` is equal to `'0'`, `True` otherwise
16
    :rtype: :class:`bool`
17
18
    **Examples:**
19
20
    .. code-block:: python
21
22
       >>> to_bool('0')
23
       False
24
       >>> to_bool('1')
25
       True
26
       >>> to_bool('-1')
27
       True
28
    """
29 1
    return int(value) != 0
30
31
32 1
def to_belligerent(value):
33 1
    return Belligerents.get_by_value(int(value))
34
35
36 1
def to_skill(value):
37 1
    return Skills.get_by_value(int(value))
38
39
40 1
def to_unit_type(value):
41 1
    return UnitTypes.get_by_value(value.lower())
42
43
44 1
def to_air_force(value):
45 1
    if value == NULL:
46 1
        return AirForces.vvs_rkka
47 1
    elif value:
48
        return AirForces.get_by_value(value)
49