From 4ce3720993e0533723cf967cb0941eec441dc40f Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Mon, 20 Jan 2025 12:05:17 +0100
Subject: [PATCH] Store relevant lines in Booking, calc ending index from their
 number.

---
 ledger.py | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/ledger.py b/ledger.py
index eee9c5d..2a1fdd6 100755
--- a/ledger.py
+++ b/ledger.py
@@ -60,9 +60,11 @@ class Booking:
     """Represents lines of individual booking."""
     # pylint: disable=too-few-public-methods
 
-    def __init__(self, id_: int, idx_start_end: tuple[int, int]) -> None:
+    def __init__(self, id_: int, idx_start: int, b_lines: list[str]) -> None:
         self.id_ = id_
-        self.idx_start, self.idx_end = idx_start_end
+        self.idx_start = idx_start
+        self.b_lines = b_lines
+        self.idx_end = self.idx_start + len(self.b_lines)
 
 
 class Handler(PlomHttpHandler):
@@ -97,17 +99,18 @@ class Server(PlomHttpServer):
                 for line in path_dat.read_text(encoding='utf8').splitlines()]
         self.bookings: list[Booking] = []
         code_lines = [dl.code for dl in self.dat_lines]
-        in_booking = False
         last_booking_start = -1
+        b_lines: list[str] = []
         for idx, code in enumerate(code_lines + ['']):
-            if in_booking and not code:
-                in_booking = False
+            if code:
+                if not b_lines:
+                    last_booking_start = idx
+                b_lines += [code]
+            elif b_lines:
                 self.bookings += [Booking(len(self.bookings),
-                                          (last_booking_start, idx))]
+                                          last_booking_start, b_lines)]
+                b_lines.clear()
                 self.dat_lines[last_booking_start].booking = self.bookings[-1]
-            elif code and not in_booking:
-                in_booking = True
-                last_booking_start = idx
 
     @property
     def dat_lines_sans_empty(self) -> list[DatLine]:
-- 
2.30.2