Skip to content

HeavenlyStem

Bases: MixEnum

The HeavenlyStem (天干) Enum class.

Source code in src/ichingpy/enum/stem.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class HeavenlyStem(MixEnum):
    """The HeavenlyStem (天干) Enum class."""

    Jia = 1, "甲"
    Yi = 2, "乙"
    Bing = 3, "丙"
    Ding = 4, "丁"
    Wu = 5, "戊"
    Ji = 6, "己"
    Geng = 7, "庚"
    Xin = 8, "辛"
    Ren = 9, "壬"
    Gui = 10, "癸"

    def __add__(self, other: Self | int) -> "HeavenlyStem":
        """Add an integer or a HeavenlyStem to the HeavenlyStem.

        Args:
            other (int): The integer to add to the HeavenlyStem.

        Returns:
            HeavenlyStem: The resulting HeavenlyStem after addition.
        """
        return HeavenlyStem((self.value + int(other) - 1) % 10 + 1)

    def __radd__(self, other: Self | int) -> "HeavenlyStem":
        return self.__add__(other)

    def __sub__(self, other: Self | int) -> "HeavenlyStem":
        """Subtract an integer or a HeavenlyStem from the HeavenlyStem.

        Args:
            other (int): The integer to subtract from the HeavenlyStem.

        Returns:
            HeavenlyStem: The resulting HeavenlyStem after subtraction.
        """
        return HeavenlyStem((self.value - int(other) - 1) % 10 + 1)

    def __rsub__(self, other: Self | int) -> "HeavenlyStem":
        return self.__sub__(other)

__add__(other)

Add an integer or a HeavenlyStem to the HeavenlyStem.

Parameters:

Name Type Description Default
other int

The integer to add to the HeavenlyStem.

required

Returns:

Name Type Description
HeavenlyStem HeavenlyStem

The resulting HeavenlyStem after addition.

Source code in src/ichingpy/enum/stem.py
20
21
22
23
24
25
26
27
28
29
def __add__(self, other: Self | int) -> "HeavenlyStem":
    """Add an integer or a HeavenlyStem to the HeavenlyStem.

    Args:
        other (int): The integer to add to the HeavenlyStem.

    Returns:
        HeavenlyStem: The resulting HeavenlyStem after addition.
    """
    return HeavenlyStem((self.value + int(other) - 1) % 10 + 1)

__sub__(other)

Subtract an integer or a HeavenlyStem from the HeavenlyStem.

Parameters:

Name Type Description Default
other int

The integer to subtract from the HeavenlyStem.

required

Returns:

Name Type Description
HeavenlyStem HeavenlyStem

The resulting HeavenlyStem after subtraction.

Source code in src/ichingpy/enum/stem.py
34
35
36
37
38
39
40
41
42
43
def __sub__(self, other: Self | int) -> "HeavenlyStem":
    """Subtract an integer or a HeavenlyStem from the HeavenlyStem.

    Args:
        other (int): The integer to subtract from the HeavenlyStem.

    Returns:
        HeavenlyStem: The resulting HeavenlyStem after subtraction.
    """
    return HeavenlyStem((self.value - int(other) - 1) % 10 + 1)