self,
code: str,
comment: str,
- add_indent: bool = False,
- raw: Optional[str] = None
+ add_indent: bool = False
) -> None:
self.comment = comment
self.code = f'{_DEFAULT_INDENT}{code}' if add_indent else code
- if raw:
- self.raw = raw
- else:
- self.raw = self.code
- if self.comment:
- self.raw += f' ; {self.comment}'
+ self.raw = self.code + ' ; '.join([''] + [s for s in [self.comment]
+ if s])
self.booking: Optional['_Booking'] = None
self.booked: Optional[BookingLine] = None
@classmethod
def new_empty(cls) -> Self:
"""Create empty DatLine."""
- return cls('', '', raw='')
+ return cls('', '')
def copy_unbooked(self) -> 'DatLine':
- """Create DatLine of .code, .comment, .raw, but no Booking ties yet."""
- return DatLine(self.code, self.comment, raw=self.raw)
+ """Create DatLine of .code and .comment, but no Booking ties yet."""
+ return DatLine(self.code, self.comment)
@classmethod
def from_raw(cls, line: str) -> Self:
"""Parse line into new DatLine."""
halves = [t.rstrip() for t in line.split(';', maxsplit=1)]
- comment = halves[1] if len(halves) > 1 else ''
+ comment = halves[1].lstrip() if len(halves) > 1 else ''
code = halves[0]
- return cls(code, comment, raw=line)
+ return cls(code, comment)
@property
def comment_instructions(self) -> dict[str, str]:
@property
def gap_lines_copied(self) -> list[DatLine]:
- """Return new DatLines generated from .raw's of .gap_lines."""
+ """Return new DatLines generated from .gap_lines."""
return [dat_line.copy_unbooked() for dat_line in self.gap_lines]
@property
def booked_lines_copied(self) -> list[DatLine]:
- """Return new DatLines generated from .raw's of .booked_lines."""
+ """Return new DatLines generated from .booked_lines."""
return [dat_line.copy_unbooked() for dat_line in self.booked_lines]
@property
def save(self) -> None:
"""Save current state to ._path_dat."""
- self._path_dat.write_text(
- '\n'.join([line.raw for line in self.dat_lines]), encoding='utf8')
+ text = '\n'.join([line.raw for line in self.dat_lines])
+ self._path_dat.write_text(text, encoding='utf8')
self.load()
def _hash_dat_lines(self) -> int: