Skip to content

Commit

Permalink
Detect and assign unit within cable length attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
formatc1702 committed Nov 16, 2020
1 parent dec64ab commit 694f3a3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,20 @@ def __post_init__(self) -> None:
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
Expand Down

0 comments on commit 694f3a3

Please sign in to comment.