Passed
Pull Request — main (#235)
by Yohann
01:33
created

pincer.utils.color   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 17
dl 0
loc 53
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Color.rbg() 0 9 1
A Color.hex() 0 9 1
A Color.__init__() 0 10 2
1
from typing import Union
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
3
4
class Color:
5
    """
6
    A color in RGB.
7
8
    Parameters
9
    ---------
10
    c : Union[:class:`str`,:class:`int`]
11
        The hex color in the format ``#NNNNNN`` or an int with the RGB values.
12
13
    Attributes
14
    ---------
15
    r : :class:`int`
16
        The red value for this color.
17
    g : :class:`int`
18
        The green value for this color.
19
    b : :class:`int`
20
        The blue value for this color.
21
    """
22
23
    def __init__(self, c: Union[str, int]) -> None:
24
        if isinstance(c, int):
25
            self.r = c >> 16 & 255
26
            self.g = c >> 8 & 255
27
            self.b = c & 255
28
            return
29
30
        # Conversion modified from this answer
31
        # https://stackoverflow.com/a/29643643
32
        self.r, self.g, self.b = (int(c[n + 1:n + 3], 16) for n in (0, 2, 4))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable n does not seem to be defined.
Loading history...
33
34
    @property
35
    def rbg(self):
36
        """
37
        Returns
38
        -------
39
        Tuple[:class:`int`, :class:`int` :class:`int`]
40
            Tuple value for rgb.
41
        """
42
        return self.r, self.g, self.b
43
44
    @property
45
    def hex(self):
46
        """
47
        Returns
48
        ---------
49
        str
50
            Str value for hex.
51
        """
52
        return f"{self.r:x}{self.g:x}{self.b:x}"
53