forked from MrBlenny/py-d2
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconnection.py
More file actions
40 lines (32 loc) · 1.04 KB
/
connection.py
File metadata and controls
40 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from enum import Enum
from typing import List
from typing import Optional
class Direction(Enum):
TO = "->"
FROM = "<-"
BOTH = "<->"
NONE = "--"
class Connection:
def __init__(self, shape_1: str, shape_2: str, label: Optional[str] = None, direction: Direction = Direction.TO):
self.shape_1 = shape_1
self.shape_2 = shape_2
self.label = label
self.direction = direction
def lines(self) -> List[str]:
base = f"{self.shape_1} {self.direction.value} {self.shape_2}"
if self.label:
base += f": {self.label}"
return [base]
def __repr__(self) -> str:
return "\n".join(self.lines())
def __hash__(self):
return hash((self.shape_1, self.shape_2, self.label, self.direction))
def __eq__(self, other) -> bool:
if (self.shape_1, self.shape_2, self.direction, self.label) == (
other.shape_1,
other.shape_2,
other.direction,
other.label,
):
return True
return False