Completed
Pull Request — master (#23)
by Ramon
01:34
created

jsons.classes.verbosity.Verbosity.from_value()   A

Complexity

Conditions 5

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 16
rs 9.3333
c 0
b 0
f 0
cc 5
nop 1
1
from enum import Flag
2
3
4
class Verbosity(Flag):
5
    """
6
    An enum that defines the level of verbosity of the serialization of an
7
    object.
8
    """
9
    WITH_NOTHING = 0
10
    WITH_CLASS_INFO = 10
11
    WITH_DUMP_TIME = 20
12
    WITH_EVERYTHING = WITH_CLASS_INFO | WITH_DUMP_TIME
13
14
    @staticmethod
15
    def from_value(value: any) -> 'Verbosity':
16
        """
17
        Return a ``Verbosity`` instance from the given value.
18
        :param value:
19
        :return: a ``Verbosity`` instance corresponding to ``value``.
20
        """
21
        if isinstance(value, Verbosity):
22
            return value
23
        if value in (False, None):
24
            return Verbosity.WITH_NOTHING
25
        if value is True:
26
            return Verbosity.WITH_EVERYTHING
27
        if value:
28
            return Verbosity.WITH_EVERYTHING
29
        return Verbosity.WITH_NOTHING
30