1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/types/WebColor.kt Fri Oct 23 18:40:50 2020 +0200 1.3 @@ -0,0 +1,27 @@ 1.4 +package de.uapcore.lightpit.types 1.5 + 1.6 + 1.7 +/** 1.8 + * Represents a web color in hexadezimal representation. 1.9 + * @param arg the 6 digits hex string optionally preceded by a hash symbol 1.10 + */ 1.11 +class WebColor(arg: String) { 1.12 + 1.13 + /** 1.14 + * The color representation with the leading hash symbol. 1.15 + */ 1.16 + val color: String = (if (arg.startsWith("#")) arg else "#$arg").toUpperCase() 1.17 + 1.18 + /** 1.19 + * The hex representation without the leading hash symbol. 1.20 + */ 1.21 + val hex: String = color.substring(1) 1.22 + 1.23 + init { 1.24 + require(this.color.matches(Regex("#[0-9A-F]{6}"))) { "$color is not a color" } 1.25 + } 1.26 + 1.27 + override fun toString(): String { 1.28 + return color 1.29 + } 1.30 +} 1.31 \ No newline at end of file