Fri, 23 Oct 2020 18:40:50 +0200
migrate WebColor
1 package de.uapcore.lightpit.types
4 /**
5 * Represents a web color in hexadezimal representation.
6 * @param arg the 6 digits hex string optionally preceded by a hash symbol
7 */
8 class WebColor(arg: String) {
10 /**
11 * The color representation with the leading hash symbol.
12 */
13 val color: String = (if (arg.startsWith("#")) arg else "#$arg").toUpperCase()
15 /**
16 * The hex representation without the leading hash symbol.
17 */
18 val hex: String = color.substring(1)
20 init {
21 require(this.color.matches(Regex("#[0-9A-F]{6}"))) { "$color is not a color" }
22 }
24 override fun toString(): String {
25 return color
26 }
27 }