Completed
Push — master ( 025da3...410210 )
by Oleksandr
01:36
created

parse_line()   B

Complexity

Conditions 3

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3
Metric Value
cc 3
dl 0
loc 25
ccs 12
cts 12
cp 1
crap 3
rs 8.8571
1
# -*- coding: utf-8 -*-
2
3 1
from ..converters import to_belligerent, to_skill, to_unit_type
4 1
from . import CollectingParser
5
6
7 1
class ChiefsParser(CollectingParser):
8
    """
9
    Parses ``Chiefs`` section.
10
    View :ref:`detailed description <chiefs-section>`.
11
    """
12
13 1
    def check_section_name(self, section_name):
14 1
        return section_name == "Chiefs"
15
16 1
    def parse_line(self, line):
17 1
        params = line.split()
18 1
        (uid, type_code, belligerent), params = params[0:3], params[3:]
19
20 1
        chief_type, code = type_code.split('.')
21 1
        try:
22 1
            chief_type = to_unit_type(chief_type)
23 1
        except Exception:
24
            # Use original string as unit type
25
            pass
26
27 1
        unit = {
28
            'id': uid,
29
            'code': code,
30
            'type': chief_type,
31
            'belligerent': to_belligerent(belligerent),
32
        }
33 1
        if params:
34 1
            hibernation, skill, recharge_time = params
35 1
            unit.update({
36
                'hibernation': int(hibernation),
37
                'skill': to_skill(skill),
38
                'recharge_time': float(recharge_time),
39
            })
40 1
        self.data.append(unit)
41
42 1
    def clean(self):
43
        return {'moving_units': self.data, }
44