Classes restructure
This commit is contained in:
22
src/pyrmv/classes/journey.py
Normal file
22
src/pyrmv/classes/journey.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from typing import Any, Mapping
|
||||
|
||||
from pyrmv.classes.message import Message
|
||||
from pyrmv.classes.stop import Stop
|
||||
|
||||
|
||||
class Journey:
|
||||
"""Journey object."""
|
||||
|
||||
def __init__(self, data: Mapping[str, Any]):
|
||||
self.stops = []
|
||||
self.ref = data["ref"]
|
||||
self.direction = data["Directions"]["Direction"][0]["value"]
|
||||
self.direction_flag = data["Directions"]["Direction"][0]["flag"]
|
||||
self.stops.extend(Stop(stop) for stop in data["Stops"]["Stop"])
|
||||
self.messages = []
|
||||
|
||||
if "Messages" in data:
|
||||
self.messages.extend(Message(message) for message in data["Messages"]["Message"])
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Journey with total of {len(self.stops)} stops and {len(self.messages)} messages heading {self.direction} ({self.direction_flag})"
|
Reference in New Issue
Block a user