module

Kebab::Convert

Built-in converters for the standard library types kebab converts out of the box, plus the failure factory for writing your own.

A converter is anything responding to convert(input : String) : T | Kebab::Convert::Failure. Attach one to a field with @[Kebab::Option(converter: MyConverter)] or @[Kebab::Argument(converter: MyConverter)].

A converter that also defines collect(values : Array(T)) : F | Kebab::Convert::Failure makes its option repeatable: every occurrence goes through convert, then collect builds the field (of type F) from all of them. On the last positional argument, collect folds the remaining positionals the same way. collect is never called with an empty array. An absent field uses its default instead.

On an Array(T) field, convert may return Array(T) to yield several elements from one value (like splitting on commas).

Instance methods

convert(type : String.class, raw : String) : String | Failure
Source
convert(type : Int8.class, raw : String) : Int8 | Failure
Source
convert(type : Int16.class, raw : String) : Int16 | Failure
Source
convert(type : Int32.class, raw : String) : Int32 | Failure
Source
convert(type : Int64.class, raw : String) : Int64 | Failure
Source
convert(type : Int128.class, raw : String) : Int128 | Failure
Source
convert(type : UInt8.class, raw : String) : UInt8 | Failure
Source
convert(type : UInt16.class, raw : String) : UInt16 | Failure
Source
convert(type : UInt32.class, raw : String) : UInt32 | Failure
Source
convert(type : UInt64.class, raw : String) : UInt64 | Failure
Source
convert(type : UInt128.class, raw : String) : UInt128 | Failure
Source
convert(type : Float32.class, raw : String) : Float32 | Failure
Source
convert(type : Float64.class, raw : String) : Float64 | Failure
Source
convert(type : T.class, raw : String) : T | Failure forall T
Source
failure(reason : String | Nil = nil, *, name : String | Nil = nil) : Failure

Builds a Failure for a converter to return.

reason is the parenthetical shown after the default message. name overrides the rendered noun for the target type (e.g. "whole number" instead of "Int32"). Both are optional.

Source

Nested types