Skip to content

Commit

Permalink
Updated parse.py
Browse files Browse the repository at this point in the history
-Renamed update_selection to _update_selection since it is "private"
-Simplified _update_selection
  • Loading branch information
TaperChipmunk32 committed Sep 27, 2024
1 parent 7e9fde1 commit 5f29642
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions machine/scripture/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,32 @@ def get_books(books: Union[str, List[str]]) -> Set[int]:
subtraction = True
book_id = book_id[1:]
if book_id == "NT":
book_set = update_selection(book_set, set(range(40, 67)), subtraction)
book_set = _update_selection(book_set, set(range(40, 67)), subtraction)
elif book_id == "OT":
book_set = update_selection(book_set, set(range(1, 40)), subtraction)
book_set = _update_selection(book_set, set(range(1, 40)), subtraction)
elif "-" in book_id:
ends = book_id.split("-")
if len(ends) != 2 or book_id_to_number(ends[0]) == 0 or book_id_to_number(ends[1]) == 0:
raise ValueError(f"{book_id} is an invalid book range.")
if book_id_to_number(ends[0]) >= book_id_to_number(ends[1]):
raise ValueError(f"{book_id} is an invalid book range. {ends[1]} precedes {ends[0]}.")
book_set = update_selection(
book_set = _update_selection(
book_set, set(range(book_id_to_number(ends[0]), book_id_to_number(ends[1]) + 1)), subtraction
)
else:
book_num = book_id_to_number(book_id)
if book_num == 0:
raise ValueError(f"{book_id} is an invalid book ID.")
book_set = update_selection(book_set, {book_num}, subtraction)
book_set = _update_selection(book_set, {book_num}, subtraction)
return book_set


def update_selection(book_set: Set[int], book_nums: Set[int], subtraction: bool) -> Set[int]:
def _update_selection(book_set: Set[int], book_nums: Set[int], subtraction: bool) -> Set[int]:
if subtraction:
if book_nums.issubset(book_set):
book_set.difference_update(book_nums)
else:
book_ids = set()
for book_num in book_nums:
book_ids.add(book_number_to_id(book_num))
book_ids = {book_number_to_id(book_num) for book_num in book_nums}
raise ValueError(f"{book_ids} cannot be removed as it is not in the existing book selection.")
else:
book_set.update(book_nums)
Expand Down

0 comments on commit 5f29642

Please sign in to comment.