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

il2fb.parsers.mission.sections.BuildingsParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 24
ccs 11
cts 11
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse_line() 0 11 1
A check_section_name() 0 2 1
A clean() 0 2 1
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 Building(BaseStructure):
11 1
    __slots__ = ['id', 'belligerent', 'code', 'pos', 'rotation_angle', ]
12
13 1
    def __init__(self, id, belligerent, code, pos, rotation_angle):
14 1
        self.id = id
15 1
        self.belligerent = belligerent
16 1
        self.code = code
17 1
        self.pos = pos
18 1
        self.rotation_angle = rotation_angle
19
20 1
    def __repr__(self):
21 1
        return "<Building '{0}'>".format(self.id)
22
23
24 1
class BuildingsParser(CollectingParser):
25
    """
26
    Parses ``Buildings`` section.
27
    View :ref:`detailed description <buildings-section>`.
28
    """
29
30 1
    def check_section_name(self, section_name):
31 1
        return section_name == "Buildings"
32
33 1
    def parse_line(self, line):
34 1
        params = line.split()
35 1
        oid, building_object, belligerent = params[:3]
36 1
        pos_x, pos_y, rotation_angle = params[3:]
37 1
        code = building_object.split('$')[1]
38 1
        self.data.append(Building(
39
            id=oid,
40
            belligerent=to_belligerent(belligerent),
41
            code=code,
42
            pos=Point2D(pos_x, pos_y),
43
            rotation_angle=float(rotation_angle),
44
        ))
45
46 1
    def clean(self):
47
        return {'buildings': self.data, }
48