| Total Complexity | 8 |
| Total Lines | 24 |
| Duplicated Lines | 0 % |
| 1 | from pytesla import Vehicle |
||
| 18 | class ResultSets(object): |
||
| 19 | |||
| 20 | def selector(self, output): |
||
| 21 | if isinstance(output, Vehicle): |
||
| 22 | return self.parse(output, FieldLists.VEHICLE) |
||
| 23 | else: |
||
| 24 | return output |
||
| 25 | |||
| 26 | def formatter(self, output): |
||
| 27 | formatted = [] |
||
| 28 | if isinstance(output, list): |
||
| 29 | for o in output: |
||
| 30 | formatted.append(self.selector(o)) |
||
| 31 | else: |
||
| 32 | formatted = self.selector(output) |
||
| 33 | return formatted |
||
| 34 | |||
| 35 | def _getval(self, obj, field): |
||
| 36 | return self.selector(getattr(obj, field)) |
||
| 37 | |||
| 38 | def parse(self, output, field_list): |
||
| 39 | instance_data = {field: self._getval(output, field) |
||
| 40 | for field in field_list} |
||
| 41 | return instance_data |
||
| 42 |