Skip to content

EarthlyBranch

Bases: MixEnum

The EarthlyBranch (地支) Enum class.

Source code in src/ichingpy/enum/branch.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class EarthlyBranch(MixEnum):
    """The EarthlyBranch (地支) Enum class."""

    Zi = 1, "子"
    Chou = 2, "丑"
    Yin = 3, "寅"
    Mao = 4, "卯"
    Chen = 5, "辰"
    Si = 6, "巳"
    Wu = 7, "午"
    Wei = 8, "未"
    Shen = 9, "申"
    You = 10, "酉"
    Xu = 11, "戌"
    Hai = 12, "亥"

    @property
    def phase(self) -> FivePhase:
        """Return the FivePhases associated with the EarthlyBranch."""
        return PHASE_MAPPING[self.name]

    @property
    def label(self) -> str:
        """Return the label of the EarthlyBranch."""
        return f"{self._label}"

    @label.setter
    def label(self, value: str) -> None:
        """Sets the label of the EarthlyBranch."""
        self._label = value

    @property
    def label_with_phase(self) -> str:
        """Return the label of the EarthlyBranch."""
        return f"{self._label}{self.phase.label}"

    @property
    def name_en(self) -> str:
        return f"{self.name.ljust(4)} ({str(self.value).ljust(2)}) {self.phase.name.ljust(5)}"

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

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

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

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

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

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

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

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

label property writable

Return the label of the EarthlyBranch.

label_with_phase property

Return the label of the EarthlyBranch.

phase property

Return the FivePhases associated with the EarthlyBranch.

__add__(other)

Add an integer or an EarthlyBranch to the EarthlyBranch.

Parameters:

Name Type Description Default
other int

The integer to add to the EarthlyBranch.

required

Returns:

Name Type Description
EarthlyBranch EarthlyBranch

The resulting EarthlyBranch after addition.

Source code in src/ichingpy/enum/branch.py
62
63
64
65
66
67
68
69
70
71
def __add__(self, other: Self | int) -> "EarthlyBranch":
    """Add an integer or an EarthlyBranch to the EarthlyBranch.

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

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

__sub__(other)

Subtract an integer or an EarthlyBranch from the EarthlyBranch.

Parameters:

Name Type Description Default
other int

The integer to subtract from the EarthlyBranch.

required

Returns:

Name Type Description
EarthlyBranch EarthlyBranch

The resulting EarthlyBranch after subtraction.

Source code in src/ichingpy/enum/branch.py
76
77
78
79
80
81
82
83
84
85
def __sub__(self, other: Self | int) -> "EarthlyBranch":
    """Subtract an integer or an EarthlyBranch from the EarthlyBranch.

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

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