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")
    "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), Right(3 s), Right(3.0 s))

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

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