| Total Complexity | 8 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| 1 | # -*- coding: utf-8 -*- |
||
| 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 |