Packages
caffeine_lang
6.2.2
6.3.1
6.3.0
6.2.2
6.2.1
6.2.0
6.1.2
6.1.1
6.1.0
6.0.0
5.6.0
5.5.0
5.4.4
5.4.3
5.4.2
5.4.1
5.4.0
5.3.0
5.2.0
5.1.1
5.1.0
5.0.12
5.0.11
5.0.10
5.0.8
5.0.7
5.0.6
5.0.5
5.0.4
5.0.1
5.0.0
4.10.0
4.9.0
4.8.3
4.8.2
4.8.1
4.8.0
4.7.9
4.7.8
4.7.7
4.7.6
4.7.5
4.6.7
4.6.6
4.6.5
4.6.4
4.6.3
4.6.2
4.6.0
4.5.1
4.5.0
4.4.4
4.4.3
4.4.1
4.4.0
4.3.7
4.3.6
3.0.6
3.0.5
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.0.2
1.0.1
0.1.0
0.0.24
0.0.23
0.0.22
0.0.21
0.0.20
0.0.19
0.0.18
0.0.17
0.0.16
0.0.15
0.0.14
0.0.13
0.0.12
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.2
0.0.1
A compiler for generating reliability artifacts from service expectation definitions.
Current section
Files
Jump to
Current section
Files
src/caffeine_lang@value.erl
-module(caffeine_lang@value).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/caffeine_lang/value.gleam").
-export([duration_unit_to_string/1, duration_unit_from_string/1, duration_to_milliseconds/2, to_string/1, to_preview_string/1, classify/1, extract_string/1, extract_int/1, extract_float/1, extract_percentage/1, extract_bool/1, extract_duration/1, extract_dict/1, extract_string_dict/1]).
-export_type([value/0, duration_unit/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type value() :: {string_value, binary()} |
{int_value, integer()} |
{float_value, float()} |
{percentage_value, float()} |
{bool_value, boolean()} |
{list_value, list(value())} |
{dict_value, gleam@dict:dict(binary(), value())} |
{duration_value, float(), duration_unit()} |
nil_value |
{external_indicator_value,
binary(),
gleam@dict:dict(binary(), value()),
gleam@option:option(binary())}.
-type duration_unit() :: millisecond | second | minute | hour | day.
-file("src/caffeine_lang/value.gleam", 47).
?DOC(false).
-spec duration_unit_to_string(duration_unit()) -> binary().
duration_unit_to_string(Unit) ->
case Unit of
millisecond ->
<<"ms"/utf8>>;
second ->
<<"s"/utf8>>;
minute ->
<<"m"/utf8>>;
hour ->
<<"h"/utf8>>;
day ->
<<"d"/utf8>>
end.
-file("src/caffeine_lang/value.gleam", 59).
?DOC(false).
-spec duration_unit_from_string(binary()) -> {ok, duration_unit()} |
{error, nil}.
duration_unit_from_string(Raw) ->
case Raw of
<<"ms"/utf8>> ->
{ok, millisecond};
<<"s"/utf8>> ->
{ok, second};
<<"m"/utf8>> ->
{ok, minute};
<<"h"/utf8>> ->
{ok, hour};
<<"d"/utf8>> ->
{ok, day};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 72).
?DOC(false).
-spec duration_to_milliseconds(float(), duration_unit()) -> float().
duration_to_milliseconds(Amount, Unit) ->
case Unit of
millisecond ->
Amount;
second ->
Amount * 1000.0;
minute ->
Amount * 60000.0;
hour ->
Amount * 3600000.0;
day ->
Amount * 86400000.0
end.
-file("src/caffeine_lang/value.gleam", 84).
?DOC(false).
-spec to_string(value()) -> binary().
to_string(Value) ->
case Value of
{string_value, S} ->
S;
{int_value, I} ->
erlang:integer_to_binary(I);
{float_value, F} ->
gleam_stdlib:float_to_string(F);
{percentage_value, F@1} ->
gleam_stdlib:float_to_string(F@1);
{bool_value, true} ->
<<"true"/utf8>>;
{bool_value, false} ->
<<"false"/utf8>>;
{list_value, Items} ->
<<<<"["/utf8,
(begin
_pipe = Items,
_pipe@1 = gleam@list:map(_pipe, fun to_string/1),
gleam@string:join(_pipe@1, <<", "/utf8>>)
end)/binary>>/binary,
"]"/utf8>>;
{dict_value, D} ->
<<<<"{"/utf8,
(begin
_pipe@2 = D,
_pipe@3 = maps:to_list(_pipe@2),
_pipe@4 = gleam@list:map(
_pipe@3,
fun(Pair) ->
<<<<(erlang:element(1, Pair))/binary,
": "/utf8>>/binary,
(to_string(erlang:element(2, Pair)))/binary>>
end
),
gleam@string:join(_pipe@4, <<", "/utf8>>)
end)/binary>>/binary,
"}"/utf8>>;
{duration_value, Amount, Unit} ->
<<(gleam_stdlib:float_to_string(Amount))/binary,
(duration_unit_to_string(Unit))/binary>>;
nil_value ->
<<""/utf8>>;
{external_indicator_value, Source, _, _} ->
<<<<"from "/utf8, Source/binary>>/binary, " {...}"/utf8>>
end.
-file("src/caffeine_lang/value.gleam", 110).
?DOC(false).
-spec to_preview_string(value()) -> binary().
to_preview_string(Value) ->
case Value of
{string_value, S} ->
<<<<"\""/utf8, S/binary>>/binary, "\""/utf8>>;
{int_value, I} ->
erlang:integer_to_binary(I);
{float_value, F} ->
gleam_stdlib:float_to_string(F);
{percentage_value, F@1} ->
<<(gleam_stdlib:float_to_string(F@1))/binary, "%"/utf8>>;
{bool_value, true} ->
<<"true"/utf8>>;
{bool_value, false} ->
<<"false"/utf8>>;
{list_value, _} ->
<<"List"/utf8>>;
{dict_value, _} ->
<<"Dict"/utf8>>;
{duration_value, Amount, Unit} ->
<<(gleam_stdlib:float_to_string(Amount))/binary,
(duration_unit_to_string(Unit))/binary>>;
nil_value ->
<<"Nil"/utf8>>;
{external_indicator_value, Source, _, _} ->
<<<<"ExternalIndicator("/utf8, Source/binary>>/binary, ")"/utf8>>
end.
-file("src/caffeine_lang/value.gleam", 130).
?DOC(false).
-spec classify(value()) -> binary().
classify(Value) ->
case Value of
{string_value, _} ->
<<"String"/utf8>>;
{int_value, _} ->
<<"Int"/utf8>>;
{float_value, _} ->
<<"Float"/utf8>>;
{percentage_value, _} ->
<<"Percentage"/utf8>>;
{bool_value, _} ->
<<"Bool"/utf8>>;
{list_value, _} ->
<<"List"/utf8>>;
{dict_value, _} ->
<<"Dict"/utf8>>;
{duration_value, _, _} ->
<<"Duration"/utf8>>;
nil_value ->
<<"Nil"/utf8>>;
{external_indicator_value, _, _, _} ->
<<"ExternalIndicator"/utf8>>
end.
-file("src/caffeine_lang/value.gleam", 147).
?DOC(false).
-spec extract_string(value()) -> {ok, binary()} | {error, nil}.
extract_string(Value) ->
case Value of
{string_value, S} ->
{ok, S};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 156).
?DOC(false).
-spec extract_int(value()) -> {ok, integer()} | {error, nil}.
extract_int(Value) ->
case Value of
{int_value, I} ->
{ok, I};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 165).
?DOC(false).
-spec extract_float(value()) -> {ok, float()} | {error, nil}.
extract_float(Value) ->
case Value of
{float_value, F} ->
{ok, F};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 174).
?DOC(false).
-spec extract_percentage(value()) -> {ok, float()} | {error, nil}.
extract_percentage(Value) ->
case Value of
{percentage_value, F} ->
{ok, F};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 183).
?DOC(false).
-spec extract_bool(value()) -> {ok, boolean()} | {error, nil}.
extract_bool(Value) ->
case Value of
{bool_value, B} ->
{ok, B};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 192).
?DOC(false).
-spec extract_duration(value()) -> {ok, {float(), duration_unit()}} |
{error, nil}.
extract_duration(Value) ->
case Value of
{duration_value, Amount, Unit} ->
{ok, {Amount, Unit}};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 201).
?DOC(false).
-spec extract_dict(value()) -> {ok, gleam@dict:dict(binary(), value())} |
{error, nil}.
extract_dict(Value) ->
case Value of
{dict_value, D} ->
{ok, D};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 211).
?DOC(false).
-spec extract_string_dict(value()) -> {ok, gleam@dict:dict(binary(), binary())} |
{error, nil}.
extract_string_dict(Value) ->
case Value of
{dict_value, D} ->
_pipe = D,
_pipe@1 = maps:to_list(_pipe),
_pipe@2 = gleam@list:try_map(
_pipe@1,
fun(Pair) -> case erlang:element(2, Pair) of
{string_value, S} ->
{ok, {erlang:element(1, Pair), S}};
_ ->
{error, nil}
end end
),
gleam@result:map(_pipe@2, fun maps:from_list/1);
_ ->
{error, nil}
end.