Skip to content

Commit

Permalink
refactor ChiefsSectionParser
Browse files Browse the repository at this point in the history
  • Loading branch information
o3bvv committed Jan 6, 2016
1 parent 1011016 commit 2095ece
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions il2fb/parsers/mission/sections/chiefs.py
Expand Up @@ -18,19 +18,15 @@ def check_section_name(self, section_name):

def parse_line(self, line):
params = line.split()
(uid, type_code, belligerent), params = params[0:3], params[3:]
(uid, type__code, belligerent), params = params[0:3], params[3:]

chief_type, code = type_code.split('.')
try:
chief_type = to_unit_type(chief_type)
except Exception:
# Use original string as unit type
pass
type_code, unit_code = type__code.split('.')
unit_type = self._get_unit_type(type_code)

unit = {
'id': uid,
'code': code,
'type': chief_type,
'code': unit_code,
'type': unit_type,
'belligerent': to_belligerent(belligerent),
}
if params:
Expand All @@ -42,6 +38,14 @@ def parse_line(self, line):
})
self.data.append(unit)

@staticmethod
def _get_unit_type(type_code):
try:
return to_unit_type(type_code)
except:
# Use original string as unit type
return type_code

def clean(self):
return {'moving_units': self.data, }

Expand Down

0 comments on commit 2095ece

Please sign in to comment.