Skip to content

Commit

Permalink
Update get_chapters to work more similarly to get_books (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac091 authored Dec 4, 2023
1 parent 644f256 commit 1df88d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 10 additions & 9 deletions machine/scripture/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ def get_books(books: Union[str, List[str]]) -> Set[int]:
# Output format: { book_num: [chapters] }
# An empty list, i.e. book_num: [] signifies the inclusion of all chapters
def get_chapters(
chapter_selections: str, versification: Versification = ORIGINAL_VERSIFICATION
chapter_selections: Union[str, List[str]], versification: Versification = ORIGINAL_VERSIFICATION
) -> Dict[int, List[int]]:
chapters = {}

if ";" not in chapter_selections and not any(
s.isdigit() and (i == len(chapter_selections) - 1 or not chapter_selections[i + 1].isalpha())
for i, s in enumerate(chapter_selections)
): # Backwards compatibility with get_books syntax:
sections = chapter_selections.split(",")
else:
sections = chapter_selections.split(";")
if isinstance(chapter_selections, str):
if ";" not in chapter_selections and not any(
s.isdigit() and (i == len(chapter_selections) - 1 or not chapter_selections[i + 1].isalpha())
for i, s in enumerate(chapter_selections)
): # Backwards compatibility with get_books syntax:
chapter_selections = chapter_selections.split(",")
else:
chapter_selections = chapter_selections.split(";")

for section in sections:
for section in chapter_selections:
section = section.strip()

if section.startswith("-"): # Subtraction
Expand Down
1 change: 1 addition & 0 deletions tests/scripture/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_get_books() -> None:


def test_get_chapters() -> None:
assert get_chapters([]) == {}
assert get_chapters("MAL") == {39: []}
assert get_chapters("GEN,EXO") == {1: [], 2: []}
assert get_chapters("1JN,2JN") == {62: [], 63: []}
Expand Down

0 comments on commit 1df88d4

Please sign in to comment.