|
1 package de.uapcore.lightpit.types |
|
2 |
|
3 |
|
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) { |
|
9 |
|
10 /** |
|
11 * The color representation with the leading hash symbol. |
|
12 */ |
|
13 val color: String = (if (arg.startsWith("#")) arg else "#$arg").toUpperCase() |
|
14 |
|
15 /** |
|
16 * The hex representation without the leading hash symbol. |
|
17 */ |
|
18 val hex: String = color.substring(1) |
|
19 |
|
20 init { |
|
21 require(this.color.matches(Regex("#[0-9A-F]{6}"))) { "$color is not a color" } |
|
22 } |
|
23 |
|
24 override fun toString(): String { |
|
25 return color |
|
26 } |
|
27 } |