Skip to content

Commit

Permalink
docs: Enum Jewish Month
Browse files Browse the repository at this point in the history
  • Loading branch information
essel-dev committed Jun 21, 2024
1 parent 6e7d59c commit 4b7d6fd
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 17 deletions.
7 changes: 7 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
exclude_patterns: list[str] = []

autodoc_class_signature: str = 'separated'
autodoc_default_options: dict[str, str | bool | None] = {
'members': True,
'member-order': 'alphabetical',
'special-members': '__init__, __str__, __repr__',
'undoc-members': False,
'exclude-members': '__weakref__',
}

add_module_names: bool = False
nitpicky = True # pylint: disable=invalid-name
Expand Down
4 changes: 2 additions & 2 deletions docs/source/definitions.rst → docs/source/constants.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Event and action constants
==========================
Constants
=========

Shabbos
-------
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ Contents

quickstart
examples
definitions
constants
reference
22 changes: 18 additions & 4 deletions docs/source/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,42 @@ API Reference

.. currentmodule:: jewcal

The JewCal Class
----------------

.. autoclass:: JewCal
:members:
:exclude-members: year, month, day, gregorian_date, shabbos, yomtov, category

The Jewish Date
----------------

.. autoclass:: JewishDate
:members:
:exclude-members: __init__

.. autoclass:: Month
:members:
:member-order: bysource
:undoc-members:

The Events
----------

.. autoclass:: Events
:members:
:exclude-members: __init__

The Zmanim
----------

.. autoclass:: Location
:members:
:exclude-members: __init__

.. autoclass:: Zmanim
:members:


Deprecated
~~~~~~~~~~
----------

.. autoproperty:: JewCal.year
.. autoproperty:: JewCal.month
Expand Down
3 changes: 2 additions & 1 deletion src/jewcal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .core import JewCal
from .models.events import Events
from .models.jewish_date import JewishDate
from .models.jewish_date import JewishDate, Month
from .models.zmanim import Location, Zmanim

Jewcal = JewCal
Expand All @@ -34,6 +34,7 @@ def __getattr__(self, name: str) -> ModuleType:
__all__ = [
'JewCal',
'JewishDate',
'Month',
'Events',
'Location',
'Zmanim',
Expand Down
9 changes: 5 additions & 4 deletions src/jewcal/models/jewish_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,24 @@ def __str__(self) -> str:
return self.name.capitalize().replace('_', ' ')

@classmethod
def get(cls: type[Month], number: int, *, leap: bool) -> Month:
def get(cls: type[Month], number: int, *, is_leap: bool) -> Month:
"""Get the enum member.
Regarding the months Adar, Adar 1 and 2:
- If the Jewish year is non-leap, it returns Adar.
- If the Jewish year is leap, it returns Adar 1 or Adar 2.
Args:
number: The month number.
leap: Is the Jewish year a leap year.
is_leap: Is the Jewish year a leap year.
Returns:
The enum member.
"""
match number:
case 12:
return Month.ADAR_1 if leap else Month.ADAR
return Month.ADAR_1 if is_leap else Month.ADAR
case _:
return Month(number)

Expand Down Expand Up @@ -86,6 +87,6 @@ def __str__(self) -> str:
"""
return (
f'{self.day}'
f' {Month.get(self.month, leap=self._is_leap_year)}'
f' {Month.get(self.month, is_leap=self._is_leap_year)}'
f' {self.year}'
)
10 changes: 5 additions & 5 deletions tests/jewcal/models/test_jewish_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def test_month_to_string(self) -> None:
def test_month_number_to_enum_member(self) -> None:
"""Test month number to enum member."""
# non-leap year
self.assertEqual(Month.get(1, leap=False), Month.NISAN)
self.assertEqual(Month.get(12, leap=False), Month.ADAR)
self.assertEqual(Month.get(1, is_leap=False), Month.NISAN)
self.assertEqual(Month.get(12, is_leap=False), Month.ADAR)

# leap year
self.assertEqual(Month.get(1, leap=True), Month.NISAN)
self.assertEqual(Month.get(12, leap=True), Month.ADAR_1)
self.assertEqual(Month.get(13, leap=True), Month.ADAR_2)
self.assertEqual(Month.get(1, is_leap=True), Month.NISAN)
self.assertEqual(Month.get(12, is_leap=True), Month.ADAR_1)
self.assertEqual(Month.get(13, is_leap=True), Month.ADAR_2)


class JewishDateTestCase(TestCase):
Expand Down

0 comments on commit 4b7d6fd

Please sign in to comment.