From e54b0ba6174d85d225711c872e24ed8510c65cd1 Mon Sep 17 00:00:00 2001 From: Noam Nol Date: Sun, 15 Sep 2024 18:38:09 +0300 Subject: [PATCH] Update docs --- README.md | 24 ++++++++++++++++-------- gematriapy/gematria.py | 19 +++++++++++++------ tests/test_to_hebrew.py | 11 +++++++++++ 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index acf43be..db51b7c 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,21 @@ pip install gematriapy ## Usage **`to_hebrew`**: + ```python -import gematriapy -gematriapy.to_hebrew(3) # => "ג" +>>> import gematriapy +>>> gematriapy.to_hebrew(3) +"ג" ``` ```python -gematriapy.to_hebrew(15) # => "טו" +>>> gematriapy.to_hebrew(15) +"טו" ``` ```python -gematriapy.to_hebrew(822) # => "תתכב" +>>> gematriapy.to_hebrew(822) +"תתכב" ``` > **NOTE**: Numbers greater than 999 are not supported yet. @@ -29,15 +33,19 @@ gematriapy.to_hebrew(822) # => "תתכב"
**`to_number`**: + ```python -import gematriapy -gematriapy.to_number("ג") # => 3 +>>> import gematriapy +>>> gematriapy.to_number("ג") +3 ``` ```python -gematriapy.to_number("טו") # => 15 +>>> gematriapy.to_number("טו") +15 ``` ```python -gematriapy.to_number("אבא") # => 4 +>>> gematriapy.to_number("אבא") +4 ``` diff --git a/gematriapy/gematria.py b/gematriapy/gematria.py index e7edfa3..2623242 100644 --- a/gematriapy/gematria.py +++ b/gematriapy/gematria.py @@ -39,11 +39,14 @@ def to_hebrew(number: int) -> str: """ - Convert number to Hebrew letter(s). + Convert a number to Hebrew letter(s). Examples: - to_hebrew(2) # => "ב" - to_hebrew(47) # => "מז" + + >>> to_hebrew(2) + 'ב' + >>> to_hebrew(47) + 'מז' """ if number <= 0: raise ValueError("Number must be bigger than zero") @@ -70,11 +73,15 @@ def to_hebrew(number: int) -> str: def to_number(hebrew: str) -> int: """ - Convert Hebrew letters to number. Ignore Non-Hebrew letters. + Sum the numerical value of all Hebrew letters in the text. + Ignore Non-Hebrew letters. Examples: - to_number("ב") # => 2 - to_number("מז") # => 47 + + >>> to_number("ב") + 2 + >>> to_number("מ״ז") + 47 """ sum = 0 for letter in hebrew: diff --git a/tests/test_to_hebrew.py b/tests/test_to_hebrew.py index 2fbe1d1..89576ee 100644 --- a/tests/test_to_hebrew.py +++ b/tests/test_to_hebrew.py @@ -7,9 +7,17 @@ def test_simple_num(self): self.assertEqual(gematriapy.to_hebrew(3), "ג") def test_15_num(self): + """ + A special case where it's traditional to replace the letters + for 10 + 5 with letters for 9 + 6. + """ self.assertEqual(gematriapy.to_hebrew(15), "טו") def test_16_num(self): + """ + A special case where it's traditional to replace the letters + for 10 + 6 with letters for 9 + 7. + """ self.assertEqual(gematriapy.to_hebrew(16), "טז") def test_random_tens_num_v1(self): @@ -24,6 +32,9 @@ def test_random_hundreds_num_v1(self): def test_random_hundreds_num_v2(self): self.assertEqual(gematriapy.to_hebrew(499), "תצט") + def test_random_hundreds_num_v3(self): + self.assertEqual(gematriapy.to_hebrew(766), "תשסו") + def test_bigger_than_800_num(self): self.assertEqual(gematriapy.to_hebrew(822), "תתכב")