universe@149: package de.uapcore.lightpit.types universe@149: universe@149: universe@149: /** universe@149: * Represents a web color in hexadezimal representation. universe@149: * @param arg the 6 digits hex string optionally preceded by a hash symbol universe@149: */ universe@149: class WebColor(arg: String) { universe@149: universe@149: /** universe@149: * The color representation with the leading hash symbol. universe@149: */ universe@149: val color: String = (if (arg.startsWith("#")) arg else "#$arg").toUpperCase() universe@149: universe@149: /** universe@149: * The hex representation without the leading hash symbol. universe@149: */ universe@149: val hex: String = color.substring(1) universe@149: universe@149: init { universe@149: require(this.color.matches(Regex("#[0-9A-F]{6}"))) { "$color is not a color" } universe@149: } universe@149: universe@149: override fun toString(): String { universe@149: return color universe@149: } universe@149: }