1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use std::fmt;

/// 16 basic colours with 18 names!
#[derive(Debug)]
pub enum Basic {
    #[allow(missing_docs)]
    Black,
    #[allow(missing_docs)]
    White,
    #[allow(missing_docs)]
    Red,
    #[allow(missing_docs)]
    Lime,
    #[allow(missing_docs)]
    Blue,
    #[allow(missing_docs)]
    Yellow,
    /// Alternate name for Aqua
    Cyan,
    /// Alternate name for Cyan
    Aqua,
    /// Alternate name for Fuchsia
    Magenta,
    /// Alternate name for Magenta
    Fuchsia,
    #[allow(missing_docs)]
    Silver,
    #[allow(missing_docs)]
    Gray,
    #[allow(missing_docs)]
    Maroon,
    #[allow(missing_docs)]
    Olive,
    #[allow(missing_docs)]
    Green,
    #[allow(missing_docs)]
    Purple,
    #[allow(missing_docs)]
    Teal,
    #[allow(missing_docs)]
    Navy,
}

impl fmt::Display for Basic {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Basic::Black => write!(f, "#000000"),
            Basic::White => write!(f, "#FFFFFF"),
            Basic::Red => write!(f, "#FF0000"),
            Basic::Lime => write!(f, "#00FF00"),
            Basic::Blue => write!(f, "#0000FF"),
            Basic::Yellow => write!(f, "#FFFF00"),
            Basic::Cyan => write!(f, "#00FFFF"),
            Basic::Aqua => write!(f, "#00FFFF"),
            Basic::Magenta => write!(f, "#FF00FF"),
            Basic::Fuchsia => write!(f, "#FF00FF"),
            Basic::Silver => write!(f, "#C0C0C0"),
            Basic::Gray => write!(f, "#808080"),
            Basic::Maroon => write!(f, "#800000"),
            Basic::Olive => write!(f, "#808000"),
            Basic::Green => write!(f, "#008000"),
            Basic::Purple => write!(f, "#800080"),
            Basic::Teal => write!(f, "#008080"),
            Basic::Navy => write!(f, "#000080"),
        }
    }
}

impl Basic {
    /// Display the hex code string as a decimal RGB Tuple
    ///
    /// ## Example
    ///
    ///```
    /// # use named_colour::Basic;
    /// # fn example() {
    /// assert_eq!("(0,255,255)", Basic::Aqua.as_rgb())
    ///
    /// # }
    ///```

    pub fn as_rgb(&self) -> String {
        match self {
            Basic::Black => crate::to_rgb("#000000"),
            Basic::White => crate::to_rgb("#FFFFFF"),
            Basic::Red => crate::to_rgb("#FF0000"),
            Basic::Lime => crate::to_rgb("#00FF00"),
            Basic::Blue => crate::to_rgb("#0000FF"),
            Basic::Yellow => crate::to_rgb("#FFFF00"),
            Basic::Cyan => crate::to_rgb("#00FFFF"),
            Basic::Aqua => crate::to_rgb("#00FFFF"),
            Basic::Magenta => crate::to_rgb("#FF00FF"),
            Basic::Fuchsia => crate::to_rgb("#FF00FF"),
            Basic::Silver => crate::to_rgb("#C0C0C0"),
            Basic::Gray => crate::to_rgb("#808080"),
            Basic::Maroon => crate::to_rgb("#800000"),
            Basic::Olive => crate::to_rgb("#808000"),
            Basic::Green => crate::to_rgb("#008000"),
            Basic::Purple => crate::to_rgb("#800080"),
            Basic::Teal => crate::to_rgb("#008080"),
            Basic::Navy => crate::to_rgb("#000080"),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn display_as_rgb() {
        assert_eq!("(0,255,255)", Basic::Aqua.as_rgb())
    }
}