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

il2fb.parsers.mission.sections.MDSScoutsParser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 28
ccs 17
cts 17
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A init_parser() 0 5 1
A _get_belligerent_name() 0 2 1
A clean() 0 5 1
A check_section_name() 0 5 2
1
# -*- coding: utf-8 -*-
2
3 1
from il2fb.commons.organization import Belligerents
4
5 1
from . import CollectingParser
6
7
8 1
class MDSScoutsParser(CollectingParser):
9
    """
10
    Parses ``MDS_Scouts`` section.
11
    View :ref:`detailed description <mds-scouts-section>`.
12
    """
13 1
    input_prefix = "MDS_Scouts_"
14 1
    output_prefix = "scouts_"
15
16 1
    def check_section_name(self, section_name):
17 1
        if not section_name.startswith(self.input_prefix):
18 1
            return False
19 1
        belligerent_name = self._get_belligerent_name(section_name)
20 1
        return bool(belligerent_name)
21
22 1
    def init_parser(self, section_name):
23 1
        super(MDSScoutsParser, self).init_parser(section_name)
24 1
        belligerent_name = self._get_belligerent_name(section_name)
25 1
        self.belligerent = Belligerents[belligerent_name]
26 1
        self.output_key = "{}{}".format(self.output_prefix, belligerent_name)
27
28 1
    def _get_belligerent_name(self, section_name):
29 1
        return section_name[len(self.input_prefix):].lower()
30
31 1
    def clean(self):
32 1
        return {
33
            self.output_key: {
34
                'belligerent': self.belligerent,
35
                'aircrafts': self.data,
36
            },
37
        }
38