Passed
Pull Request — main (#235)
by
unknown
01:36
created

pincer.utils.color   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 17
dl 0
loc 50
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 8 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
    Attributes
13
    r : :class:`int`
14
        The red value for this color.
15
    g : :class:`int`
16
        The green value for this color.
17
    b : :class:`int`
18
        The blue value for this color.
19
    """
20
21
    def __init__(self, c: Union[str, int]) -> None:
22
        if isinstance(c, int):
23
            self.r = c >> 16 & 255
24
            self.g = c >> 8 & 255
25
            self.b = c & 255
26
            return
27
28
        # Conversion modified from this answer
29
        # https://stackoverflow.com/a/29643643
30
        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...
31
32
    @property
33
    def rbg(self):
34
        """
35
        Returns
36
        -------
37
        Tuple[:class:`int`, :class:`int` :class:`int`]
38
            Tuple value for rgb.
39
        """
40
        return self.r, self.g, self.b
41
42
    @property
43
    def hex(self):
44
        """
45
        Returns
46
        str
47
            Str value for hex.
48
        """
49
        return f"{hex(self.r)[2:]}{hex(self.g)[2:]}{hex(self.b)[2:]}"
50