Squants Module

The ciris-squants module enables decoding of quantities with unit of measure from squants. For a complete list of supported dimensions, refer to the documentation. Let’s see how this works by first defining a configuration source with a few different keys mapping to Time values, each having a different unit of measure.

import ciris.{ConfigKeyType, ConfigSource}
import ciris.squants._
import squants.time.Time

val source = {
  val keyType = ConfigKeyType[String]("squants key")
  ConfigSource.fromEntries(keyType)(
    "seconds" -> "3 s",
    "minutes" -> "23 m",
    "hours" -> "12 h"
  )
}

We can then read entries from the source and decode values as Time.

val seconds = source.read("seconds").decodeValue[Time]
// seconds: ciris.ConfigEntry[ciris.api.Id,String,String,squants.time.Time] = ConfigEntry(seconds, ConfigKeyType(squants key))

val minutes = source.read("minutes").decodeValue[Time]
// minutes: ciris.ConfigEntry[ciris.api.Id,String,String,squants.time.Time] = ConfigEntry(minutes, ConfigKeyType(squants key))

val hours = source.read("hours").decodeValue[Time]
// hours: ciris.ConfigEntry[ciris.api.Id,String,String,squants.time.Time] = ConfigEntry(hours, ConfigKeyType(squants key))