Skip to content

Commit

Permalink
Move to v.0.2.0 and restyle code and usage
Browse files Browse the repository at this point in the history
  • Loading branch information
NoamNol committed Jul 5, 2021
1 parent 17e2501 commit 4579948
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 66 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ pip install gematriapy

## Usage
```python
from gematriapy import Gematria
gematria = Gematria()
gematria.number_to_hebrew(3) # => "ג"
import gematriapy
gematriapy.to_hebrew(3) # => "ג"
```

```python
gematria.number_to_hebrew(15) # => "טו"
gematriapy.to_hebrew(15) # => "טו"
```

```python
gematria.number_to_hebrew(822) # => "תתכב"
gematriapy.to_hebrew(822) # => "תתכב"
```

> **NOTE**: Numbers greater than 999 are not supported yet.
6 changes: 5 additions & 1 deletion gematriapy/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
from .gematria import Gematria
"""Convert numbers to Hebrew letters"""

__version__ = "0.2.0"

from .gematria import to_hebrew
22 changes: 12 additions & 10 deletions gematriapy/gematria.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Gematria:
_HEBREW_LETTERS = [
from collections import OrderedDict


HEBREW_LETTERS: OrderedDict = OrderedDict([
("א", 1),
("ב", 2),
("ג", 3),
Expand All @@ -22,26 +24,26 @@ class Gematria:
("ר", 200),
("ש", 300),
("ת", 400)
]
_REVERSED_HEBREW_LETTERS = _HEBREW_LETTERS[::-1]
])


def number_to_hebrew(self, number: int) -> str:
def to_hebrew(number: int) -> str:
"""
Convert number to Hebrew letter(s)
Convert number to Hebrew letter(s).
Examples:
2 = "ב"
47 = "מז"
to_hebrew(2) # => "ב"
to_hebrew(47) # => "מז"
"""
if number <= 0:
raise Exception("Number must be bigger than zero")
if number >= 1000:
raise Exception("Number bigger than 999 is not supported yet")
raise Exception("Number bigger than 999 is not yet supported")

remainder = number
heb_sum = ""
while remainder > 0:
for heb_letter, val in self._REVERSED_HEBREW_LETTERS:
for heb_letter, val in reversed(HEBREW_LETTERS.items()):
if (val <= remainder):
if remainder == 15:
heb_sum += "טו"
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import setuptools
import gematriapy

with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()

setuptools.setup(
name="gematriapy",
version="0.1.0",
version=gematriapy.__version__,
author="Noam Nol",
author_email="[email protected]",
description="Convert numbers to Hebrew letters",
description=gematriapy.__doc__,
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/NoamNol/gematriapy",
Expand Down
48 changes: 0 additions & 48 deletions tests/test_gematria.py

This file was deleted.

46 changes: 46 additions & 0 deletions tests/test_to_hebrew.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import unittest
import gematriapy


class TestGematriapy_ToHebrew(unittest.TestCase):
def test_simple_num(self):
self.assertEqual(gematriapy.to_hebrew(3), "ג")

def test_15_num(self):
self.assertEqual(gematriapy.to_hebrew(15), "טו")

def test_16_num(self):
self.assertEqual(gematriapy.to_hebrew(16), "טז")

def test_random_tens_num_v1(self):
self.assertEqual(gematriapy.to_hebrew(24), "כד")

def test_random_tens_num_v2(self):
self.assertEqual(gematriapy.to_hebrew(77), "עז")

def test_random_hundreds_num_v1(self):
self.assertEqual(gematriapy.to_hebrew(250), "רנ")

def test_random_hundreds_num_v2(self):
self.assertEqual(gematriapy.to_hebrew(499), "תצט")

def test_bigger_than_800_num(self):
self.assertEqual(gematriapy.to_hebrew(822), "תתכב")

def test_hundreds_num_that_ends_with_15(self):
self.assertEqual(gematriapy.to_hebrew(515), "תקטו")

def test_hundreds_num_that_ends_with_16(self):
self.assertEqual(gematriapy.to_hebrew(516), "תקטז")

def test_zero(self):
with self.assertRaises(Exception):
gematriapy.to_hebrew(0)

def test_negative(self):
with self.assertRaises(Exception):
gematriapy.to_hebrew(-1)

def test_too_big(self):
with self.assertRaises(Exception):
gematriapy.to_hebrew(1000)

0 comments on commit 4579948

Please sign in to comment.