lib/king_konf/decoder.rb in king_konf-0.2.0 vs lib/king_konf/decoder.rb in king_konf-0.3.0

- old
+ new

@@ -1,5 +1,7 @@ +require "king_konf/duration_decoder" + module KingKonf module Decoder extend self def boolean(value, true_values: ["true", "1"], false_values: ["false", "0"]) @@ -15,10 +17,14 @@ def string(value, **) value end + def symbol(value, **) + value.to_sym + end + def list(value, sep: ",", items: :string) value.split(sep).map {|s| public_send(items, s) } end def integer(value, **) @@ -27,8 +33,19 @@ raise ConfigError, "#{value.inspect} is not an integer" end def float(value, **) Float(value) + end + + def duration(value, **) + case value + when "" + nil + when/^\d*$/ + value.to_i + else + DurationDecoder.decode(value) + end end end end