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

clean()   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.spatial import Point2D
4 1
from il2fb.commons.structures import BaseStructure
5
6 1
from ..converters import to_belligerent
7 1
from . import CollectingParser
8
9
10 1
class Rocket(BaseStructure):
11 1
    __slots__ = [
12
        'id', 'code', 'belligerent', 'pos', 'rotation_angle', 'delay', 'count',
13
        'period', 'destination',
14
    ]
15
16 1
    def __init__(self, id, code, belligerent, pos, rotation_angle, delay,
17
                 count, period, destination):
18 1
        self.id = id
19 1
        self.code = code
20 1
        self.belligerent = belligerent
21 1
        self.pos = pos
22 1
        self.rotation_angle = rotation_angle
23 1
        self.delay = delay
24 1
        self.count = count
25 1
        self.period = period
26 1
        self.destination = destination
27
28 1
    def __repr__(self):
29 1
        return "<Rocket '{0}'>".format(self.id)
30
31
32 1
class RocketParser(CollectingParser):
33
    """
34
    Parses ``Rocket`` section.
35
    View :ref:`detailed description <rocket-section>`.
36
    """
37
38 1
    def check_section_name(self, section_name):
39 1
        return section_name == "Rocket"
40
41 1
    def parse_line(self, line):
42 1
        params = line.split()
43
44 1
        oid, code, belligerent = params[0:3]
45 1
        pos = params[3:5]
46 1
        rotation_angle, delay, count, period = params[5:9]
47 1
        destination = params[9:]
48
49 1
        self.data.append(Rocket(
50
            id=oid,
51
            code=code,
52
            belligerent=to_belligerent(belligerent),
53
            pos=Point2D(*pos),
54
            rotation_angle=float(rotation_angle),
55
            delay=float(delay),
56
            count=int(count),
57
            period=float(period),
58
            destination=Point2D(*destination) if destination else None
59
        ))
60
61 1
    def clean(self):
62
        return {'rockets': self.data}
63