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

check_section_name()   A

Complexity

Conditions 4

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4
Metric Value
cc 4
dl 0
loc 9
ccs 8
cts 8
cp 1
crap 4
rs 9.2
1
# -*- coding: utf-8 -*-
2
3 1
from ..converters import to_air_force
4 1
from . import CollectingParser
5
6
7 1
class BornPlaceAirForcesParser(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(BornPlaceAirForcesParser, 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