1"""SKIP value type of RECUR from :rfc:`7529`."""
2
3from typing import Any
4
5from icalendar.compatibility import Self
6from icalendar.enums import Enum
7from icalendar.error import JCalParsingError
8from icalendar.prop.text import vText
9
10
11class vSkip(vText, Enum):
12 """Skip values for RRULE.
13
14 These are defined in :rfc:`7529`.
15
16 OMIT is the default value.
17
18 Examples:
19
20 .. code-block:: pycon
21
22 >>> from icalendar import vSkip
23 >>> vSkip.OMIT
24 vSkip('OMIT')
25 >>> vSkip.FORWARD
26 vSkip('FORWARD')
27 >>> vSkip.BACKWARD
28 vSkip('BACKWARD')
29 """
30
31 OMIT = "OMIT"
32 FORWARD = "FORWARD"
33 BACKWARD = "BACKWARD"
34
35 __reduce_ex__ = Enum.__reduce_ex__
36
37 def __repr__(self):
38 return f"{self.__class__.__name__}({self._name_!r})"
39
40 @classmethod
41 def parse_jcal_value(cls, value: Any) -> Self:
42 """Parse a jCal value for vSkip.
43
44 Raises:
45 ~error.JCalParsingError: If the value is not a valid skip value.
46 """
47 JCalParsingError.validate_value_type(value, str, cls)
48 try:
49 return cls[value.upper()]
50 except KeyError as e:
51 raise JCalParsingError(
52 "The value must be a valid skip value.", cls, value=value
53 ) from e
54
55
56__all__ = ["vSkip"]