From 694f3a3f96820eaf1faac9e9f1b769c6dbcb072f Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Mon, 16 Nov 2020 17:51:45 +0100 Subject: [PATCH] Detect and assign unit within cable length attribute --- src/wireviz/DataClasses.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index c2d680d..a9c699d 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -214,6 +214,20 @@ class Cable: else: pass # gauge not specified + if isinstance(self.length, str): # length and unit specified + try: + l, u = self.length.split(' ') + l = float(l) + except Exception: + raise Exception('Length must be a number, or number and unit separated by a space') + self.length = l + self.length_unit = u + elif self.length is not None: # length specified, assume m + if self.gauge_unit is None: + self.length_unit = 'm' + else: + pass # length not specified + self.connections = [] if self.length_unit is None: #Default wire length units to meters if left undeclared