Sha256: edf6049dd857edec590b0b1373dcf1d54df3be9f1739a73588504c026afe2aca

Contents?: true

Size: 774 Bytes

Versions: 4

Compression:

Stored size: 774 Bytes

Contents

module KingKonf
  module Decoder
    extend self

    def boolean(value, true_values: ["true", "1"], false_values: ["false", "0"])
      if true_values.include?(value)
        true
      elsif false_values.include?(value)
        false
      else
        values = true_values + false_values
        raise ConfigError, "#{value.inspect} is not a boolean: must be one of #{values.join(', ')}"
      end
    end

    def string(value, **)
      value
    end

    def list(value, sep: ",", items: :string)
      value.split(sep).map {|s| public_send(items, s) }
    end

    def integer(value, **)
      Integer(value)
    rescue ArgumentError
      raise ConfigError, "#{value.inspect} is not an integer"
    end

    def float(value, **)
      Float(value)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
king_konf-0.2.0 lib/king_konf/decoder.rb
king_konf-0.1.10 lib/king_konf/decoder.rb
king_konf-0.1.9 lib/king_konf/decoder.rb
king_konf-0.1.8 lib/king_konf/decoder.rb