Append the reading-cost figure, refresh item 109, and read a todo.md from before C joined it

This commit is contained in:
2026-10-13 11:20:08 +02:00
parent 064bfe78f4
commit 228478061e
5 changed files with 36 additions and 9 deletions
+12 -6
View File
@@ -27,13 +27,15 @@ class Table:
def items(todo: str) -> list[Item] | Failure:
"""Each row of a todo.md's items table."""
table = table_rows(todo.splitlines(), ITEMS_HEADER)
"""Each row of a todo.md's items table, or of one from before C joined it."""
lines = todo.splitlines()
legacy = LEGACY_HEADER in lines
table = table_rows(lines, LEGACY_HEADER if legacy else ITEMS_HEADER)
if isinstance(table, Failure):
return table
items = []
for row in table.rows:
item = parse_row(row)
item = parse_row(row, legacy)
if isinstance(item, Failure):
return item
items.append(item)
@@ -57,11 +59,13 @@ def cells(row: str, count: int) -> list[str] | Failure:
return found if len(found) == count else Failure(f"this row needs {count} cells: {row}")
def parse_row(row: str) -> Item | Failure:
"""An item row, every cell checked but the goals it cites."""
found = cells(row, 11)
def parse_row(row: str, legacy: bool = False) -> Item | Failure:
"""An item row, every cell checked but the goals it cites; a legacy row has no C."""
found = cells(row, 10 if legacy else 11)
if isinstance(found, Failure):
return found
if legacy:
found.insert(6, "")
id_, release, exempt, tagline, r, s, c, a, g, goals, _ = found
if not re.fullmatch(r"[0-9]+", id_) or int(id_) < 1:
return Failure(f"the ID {id_!r} is not a positive whole number: {row}")
@@ -73,6 +77,8 @@ def parse_row(row: str) -> Item | Failure:
return Failure(f"item {id_}'s Item cell is not one bold tagline: {tagline}")
scores = {}
for name, value in zip("RSCAG", (r, s, c, a, g)):
if legacy and name == "C":
continue
if not re.fullmatch(r"[0-9]+", value) or not 1 <= int(value) <= 10:
return Failure(f"item {id_}'s {name} {value!r} is not a whole number from 1 to 10")
scores[name] = int(value)