Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
NoamNol committed Sep 15, 2024
1 parent 7bef183 commit 80741f3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,41 @@ 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.
<br/>

**`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
```
19 changes: 13 additions & 6 deletions gematriapy/gematria.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_to_hebrew.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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), "תתכב")

Expand Down

0 comments on commit 80741f3

Please sign in to comment.