Completed
Push — master ( caabd8...c07396 )
by Oleksandr
01:11
created

il2fb.parsers.mission.sections.BornPlaceAirForcesSectionParser   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 35
ccs 23
cts 23
cp 1
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A clean() 0 2 1
A _extract_section_number() 0 3 1
A parse_line() 0 3 1
A check_section_name() 0 9 4
A init_parser() 0 6 1
1
# -*- coding: utf-8 -*-
2
3 1
from ..converters import to_air_force
4 1
from . import CollectingParser
5
6
7 1
class BornPlaceAirForcesSectionParser(CollectingParser):
8
    """
9
    Parses ``BornPlaceCountriesN`` section.
10
    View :ref:`detailed description <bornplace-air-forces-section>`.
11
    """
12 1
    input_prefix = 'BornPlaceCountries'
13 1
    output_prefix = 'home_base_air_forces_'
14
15 1
    def check_section_name(self, section_name):
16 1
        if not section_name.startswith(self.input_prefix):
17 1
            return False
18 1
        try:
19 1
            self._extract_section_number(section_name)
20 1
        except ValueError:
21 1
            return False
22
        else:
23 1
            return True
24
25 1
    def init_parser(self, section_name):
26 1
        super(BornPlaceAirForcesSectionParser, self).init_parser(section_name)
27 1
        self.output_key = (
28
            "{}{}".format(self.output_prefix,
29
                          self._extract_section_number(section_name)))
30 1
        self.countries = {}
31
32 1
    def _extract_section_number(self, section_name):
33 1
        start = len(self.input_prefix)
34 1
        return int(section_name[start:])
35
36 1
    def parse_line(self, line):
37 1
        air_force = to_air_force(line.strip())
38 1
        self.data.append(air_force)
39
40 1
    def clean(self):
41
        return {self.output_key: self.data, }
42