Expression.Callbacks.Standard (expression v2.23.8)
The function callbacks for the standard function set available in FLOIP expressions.
This should be relatively swappable with another implementation.
The only requirement is the handle/3
function.
FLOIP functions are case insensitive. All functions in this callback module are implemented as lowercase names.
Some functions accept a variable amount of arguments. Elixir doesn't support variable arguments in functions.
If a function accepts a variable number of arguments the convention
is to call the <function_name>_vargs/2
callback where the context
is given as the first argument and the argument list as a second
argument.
Reserved names such as and
, if
, and or
are suffixed with an
underscore.
Link to this section Summary
Functions
Returns the absolute value of a number
Returns true
if and only if all its arguments evaluate to true
Returns the character specified by a number
Removes all non-printable characters from a text string
Returns a numeric code for the first character in a text string
Joins text strings into one text string
Defines a new date value
Calculates a new datetime based on the offset and unit provided.
Converts date stored in text to an actual date object and
formats it using strftime
formatting.
Returns only the day of the month of a date (1 to 31)
Moves a date by the given number of months
Return a list of all functions annotated with @expression_docs
Returns the first word in the given text - equivalent to WORD(text, 1)
Formats the given number in decimal format using a period and commas
Tests whether all the words are contained in text
Tests whether any of the words are contained in the text
Tests whether text starts with beginning
Tests whether expression
contains a date formatted according to our environment
Tests whether expression
is a date equal to date_string
Tests whether expression
is a date after the date date_string
Tests whether expression
contains a date before the date date_string
Tests whether an email is contained in text
Returns whether the contact is part of group with the passed in UUID
Tests whether expression
contains a number
Tests whether expression
contains a number equal to the value
Tests whether expression
contains a number greater than min
Tests whether expression
contains a number greater than or equal to min
Tests whether expression
contains a number less than max
Tests whether expression
contains a number less than or equal to max
Tests whether the text contains only phrase
Returns whether two text values are equal (case sensitive). In the case that they are, it will return the text as the match.
Tests whether expression
matches the regex pattern
Tests whether expresssion
contains a phone number.
The optional country_code argument specifies the country to use for parsing.
Tests whether phrase is contained in expression
Tests whether there the expression
has any characters in it
Tests whether expression
contains a time.
Returns only the hour of a datetime (0 to 23)
Returns one value if the condition evaluates to true
, and another value if it evaluates to false
Returns true
if the argument is a boolean.
Returns true
if the argument is a number.
Returns true
if the argument is a string.
Returns the first characters in a text string. This is Unicode safe.
Returns the number of characters in a text string
Converts a text string to lowercase
map over a list of items and apply the mapper function to every item, returning the result.
Returns the maximum value of all arguments
Returns the minimum value of all arguments
Returns only the minute of a datetime (0 to 59)
Returns only the month of a date (1 to 12)
Returns false
if the argument supplied evaluates to truth-y
Returns the current date time as UTC
Returns true
if any argument is true
.
Returns the first truthy value found or otherwise false.
Formats a number as a percentage
Returns the result of a number raised to a power - equivalent to the ^ operator
Capitalizes the first letter of every word in a text string
Formats digits in text for reading in TTS
Return the division remainder of two integers.
Removes the first word from the given text. The remaining text will be unchanged
Repeats text a given number of times
Returns the last characters in a text string. This is Unicode safe.
Returns only the second of a datetime (0 to 59)
Substitutes new_text for old_text in a text string. If instance_num is given, then only that instance will be substituted
Returns the sum of all arguments, equivalent to the + operator
Defines a time value which can be used for time arithmetic
Converts time stored in text to an actual time
Returns the current date
Returns the unicode character specified by a number
Returns a numeric code for the first character in a text string
Converts a text string to uppercase
Returns the day of the week of a date (1 for Sunday to 7 for Saturday)
Extracts the nth word from the given text string. If stop is a negative number,
then it is treated as count backwards from the end of the text. If by_spaces is
specified and is true
then the function splits the text into words only by spaces.
Otherwise the text is split by punctuation characters as well
Returns the number of words in the given text string. If by_spaces is specified and is true
then the function splits the text into words only by spaces. Otherwise the text is split by punctuation characters as well
Extracts a substring of the words beginning at start, and up to but not-including stop.
If stop is omitted then the substring will be all words from start until the end of the text.
If stop is a negative number, then it is treated as count backwards from the end of the text.
If by_spaces is specified and is true
then the function splits the text into words only by spaces.
Otherwise the text is split by punctuation characters as well
Returns only the year of a date
Link to this section Functions
abs(ctx, number)
Returns the absolute value of a number
example-1
Example 1:
When used in the following Stack expression it returns a value of type Integer: 1
.
> abs(-1)
1
When used as an expression in text, prepend it with an @
:
> "... @abs(-1) ..."
"1"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "abs(-1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 1 = result
1
iex> Expression.evaluate_as_string!(
...> "@abs(-1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"1"
and_vargs(ctx, arguments)
Returns true
if and only if all its arguments evaluate to true
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
when used with the following context:
%{"contact" => %{"age" => 32, "gender" => "F"}}
> contact.gender = "F" and contact.age >= 18
true
When used as an expression in text, prepend it with an @
:
> "... @and(contact.gender = "F", contact.age >= 18) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "and(contact.gender = \"F\", contact.age >= 18)",
...> %{"contact" => %{"age" => 32, "gender" => "F"}},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@and(contact.gender = \"F\", contact.age >= 18)",
...> %{"contact" => %{"age" => 32, "gender" => "F"}},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: false
when used with the following context:
%{"contact" => %{"age" => 32, "gender" => "?"}}
> contact.gender = "F" and contact.age >= 18
false
When used as an expression in text, prepend it with an @
:
> "... @and(contact.gender = "F", contact.age >= 18) ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "and(contact.gender = \"F\", contact.age >= 18)",
...> %{"contact" => %{"age" => 32, "gender" => "?"}},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@and(contact.gender = \"F\", contact.age >= 18)",
...> %{"contact" => %{"age" => 32, "gender" => "?"}},
...> Expression.Callbacks.Standard
...> )
"false"
char(ctx, code)
Returns the character specified by a number
> "As easy as @char(65), @char(66), @char(67)"
"As easy as A, B, C"
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "A"
.
> char(65)
"A"
When used as an expression in text, prepend it with an @
:
> "... @char(65) ..."
"A"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "char(65)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "A" = result
"A"
iex> Expression.evaluate_as_string!(
...> "@char(65)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"A"
clean(ctx, binary)
Removes all non-printable characters from a text string
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "ABC"
when used with the following context:
%{"value" => <<65, 0, 66, 0, 67>>}
> clean(value)
"ABC"
When used as an expression in text, prepend it with an @
:
> "... @clean(value) ..."
"ABC"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "clean(value)",
...> %{"value" => <<65, 0, 66, 0, 67>>},
...> Expression.Callbacks.Standard
...> )
iex> assert "ABC" = result
"ABC"
iex> Expression.evaluate_as_string!(
...> "@clean(value)",
...> %{"value" => <<65, 0, 66, 0, 67>>},
...> Expression.Callbacks.Standard
...> )
"ABC"
code(ctx, code_ast)
Returns a numeric code for the first character in a text string
> "The numeric code of A is @CODE(\"A\")"
"The numeric code of A is 65"
example-1
Example 1:
When used in the following Stack expression it returns a value of type Integer: 65
.
> code("A")
65
When used as an expression in text, prepend it with an @
:
> "... @code("A") ..."
"65"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "code(\"A\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 65 = result
65
iex> Expression.evaluate_as_string!(
...> "@code(\"A\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"65"
concatenate_vargs(ctx, arguments)
Joins text strings into one text string
> "Your name is @CONCATENATE(contact.first_name, \" \", contact.last_name)"
"Your name is name surname"
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "name surname"
when used with the following context:
%{"contact" => %{"first_name" => "name", "last_name" => "surname"}}
> concatenate(contact.first_name, " ", contact.last_name)
"name surname"
When used as an expression in text, prepend it with an @
:
> "... @concatenate(contact.first_name, " ", contact.last_name) ..."
"name surname"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "concatenate(contact.first_name, \" \", contact.last_name)",
...> %{"contact" => %{"first_name" => "name", "last_name" => "surname"}},
...> Expression.Callbacks.Standard
...> )
iex> assert "name surname" = result
"name surname"
iex> Expression.evaluate_as_string!(
...> "@concatenate(contact.first_name, \" \", contact.last_name)",
...> %{"contact" => %{"first_name" => "name", "last_name" => "surname"}},
...> Expression.Callbacks.Standard
...> )
"name surname"
date(ctx, year, month, day)
Defines a new date value
example-1
Example 1:
Construct a date from year, month, and day integers
When used in the following Stack expression it returns a value of type Date: ~D[2022-01-31]
when used with the following context:
%{"day" => 31, "month" => 1, "year" => 2022}
> date(year, month, day)
~D[2022-01-31]
When used as an expression in text, prepend it with an @
:
> "... @date(year, month, day) ..."
"2022-01-31"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "date(year, month, day)",
...> %{"day" => 31, "month" => 1, "year" => 2022},
...> Expression.Callbacks.Standard
...> )
iex> assert ~D[2022-01-31] = result
~D[2022-01-31]
iex> Expression.evaluate_as_string!(
...> "@date(year, month, day)",
...> %{"day" => 31, "month" => 1, "year" => 2022},
...> Expression.Callbacks.Standard
...> )
"2022-01-31"
datetime_add(ctx, datetime, offset, unit)
Calculates a new datetime based on the offset and unit provided.
The unit can be any of the following values:
- "Y" for years
- "M" for months
- "W" for weeks
- "D" for days
- "h" for hours
- "m" for minutes
- "s" for seconds
Specifying a negative offset results in date calculations back in time.
example-1
Example 1:
Calculates a new datetime based on the offset and unit provided.
When used in the following Stack expression it returns a value of type DateTime: ~U[2022-08-31 00:00:00Z]
when used with the following context:
%{"datetime" => ~U[2022-07-31 00:00:00Z], "offset" => "1", "unit" => "M"}
> datetime_add(datetime, offset, unit)
~U[2022-08-31 00:00:00Z]
When used as an expression in text, prepend it with an @
:
> "... @datetime_add(datetime, offset, unit) ..."
"2022-08-31T00:00:00Z"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "datetime_add(datetime, offset, unit)",
...> %{"datetime" => ~U[2022-07-31 00:00:00Z], "offset" => "1", "unit" => "M"},
...> Expression.Callbacks.Standard
...> )
iex> assert ~U[2022-08-31 00:00:00Z] = result
~U[2022-08-31 00:00:00Z]
iex> Expression.evaluate_as_string!(
...> "@datetime_add(datetime, offset, unit)",
...> %{"datetime" => ~U[2022-07-31 00:00:00Z], "offset" => "1", "unit" => "M"},
...> Expression.Callbacks.Standard
...> )
"2022-08-31T00:00:00Z"
example-2
Example 2:
Leap year handling in a leap year.
When used in the following Stack expression it returns a value of type DateTime: ~U[2020-02-29 00:00:00.000000Z]
.
> datetime_add(date(2020, 02, 28), 1, "D")
~U[2020-02-29 00:00:00.000000Z]
When used as an expression in text, prepend it with an @
:
> "... @datetime_add(date(2020, 02, 28), 1, "D") ..."
"2020-02-29T00:00:00.000000Z"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "datetime_add(date(2020, 02, 28), 1, \"D\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert ~U[2020-02-29 00:00:00.000000Z] = result
~U[2020-02-29 00:00:00.000000Z]
iex> Expression.evaluate_as_string!(
...> "@datetime_add(date(2020, 02, 28), 1, \"D\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"2020-02-29T00:00:00.000000Z"
example-3
Example 3:
Leap year handling outside of a leap year.
When used in the following Stack expression it returns a value of type DateTime: ~U[2021-03-01 00:00:00.000000Z]
.
> datetime_add(date(2021, 02, 28), 1, "D")
~U[2021-03-01 00:00:00.000000Z]
When used as an expression in text, prepend it with an @
:
> "... @datetime_add(date(2021, 02, 28), 1, "D") ..."
"2021-03-01T00:00:00.000000Z"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "datetime_add(date(2021, 02, 28), 1, \"D\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert ~U[2021-03-01 00:00:00.000000Z] = result
~U[2021-03-01 00:00:00.000000Z]
iex> Expression.evaluate_as_string!(
...> "@datetime_add(date(2021, 02, 28), 1, \"D\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"2021-03-01T00:00:00.000000Z"
example-4
Example 4:
Negative offsets
When used in the following Stack expression it returns a value of type DateTime: ~U[2020-02-28 00:00:00.000000Z]
.
> datetime_add(date(2020, 02, 29), -1, "D")
~U[2020-02-28 00:00:00.000000Z]
When used as an expression in text, prepend it with an @
:
> "... @datetime_add(date(2020, 02, 29), -1, "D") ..."
"2020-02-28T00:00:00.000000Z"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "datetime_add(date(2020, 02, 29), -1, \"D\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert ~U[2020-02-28 00:00:00.000000Z] = result
~U[2020-02-28 00:00:00.000000Z]
iex> Expression.evaluate_as_string!(
...> "@datetime_add(date(2020, 02, 29), -1, \"D\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"2020-02-28T00:00:00.000000Z"
datevalue(ctx, date)
datevalue(ctx, date, format)
Converts date stored in text to an actual date object and
formats it using strftime
formatting.
It will fallback to "%Y-%m-%d %H:%M:%S" if no formatting is supplied
example-1
Example 1:
Convert a date from a piece of text to a formatted date string
When used in the following Stack expression it returns a complex String type of default value:
"2022-01-01 00:00:00"
with the following fields:
- date of type Date .
> datevalue("2022-01-01")
%{"__value__" => "2022-01-01 00:00:00", "date" => ~D[2022-01-01]}
When used as an expression in text, prepend it with an @
:
> "... @datevalue("2022-01-01") ..."
"2022-01-01 00:00:00"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "datevalue(\"2022-01-01\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert %{"__value__" => "2022-01-01 00:00:00", "date" => ~D[2022-01-01]} = result
%{"__value__" => "2022-01-01 00:00:00", "date" => ~D[2022-01-01]}
iex> Expression.evaluate_as_string!(
...> "@datevalue(\"2022-01-01\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"2022-01-01 00:00:00"
example-2
Example 2:
Convert a date from a piece of text and read the date field
When used in the following Stack expression it returns a value of type Date: ~D[2022-01-01]
.
> datevalue("2022-01-01").date
~D[2022-01-01]
When used as an expression in text, prepend it with an @
:
> "... @datevalue("2022-01-01").date ..."
"2022-01-01"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "datevalue(\"2022-01-01\").date",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert ~D[2022-01-01] = result
~D[2022-01-01]
iex> Expression.evaluate_as_string!(
...> "@datevalue(\"2022-01-01\").date",
...> %{},
...> Expression.Callbacks.Standard
...> )
"2022-01-01"
example-3
Example 3:
Convert a date value and read the date field
When used in the following Stack expression it returns a value of type Date: ~D[2022-01-01]
.
> datevalue(date(2022, 1, 1)).date
~D[2022-01-01]
When used as an expression in text, prepend it with an @
:
> "... @datevalue(date(2022, 1, 1)).date ..."
"2022-01-01"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "datevalue(date(2022, 1, 1)).date",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert ~D[2022-01-01] = result
~D[2022-01-01]
iex> Expression.evaluate_as_string!(
...> "@datevalue(date(2022, 1, 1)).date",
...> %{},
...> Expression.Callbacks.Standard
...> )
"2022-01-01"
day(ctx, date)
Returns only the day of the month of a date (1 to 31)
example-1
Example 1:
Getting today's day of the month
When used in the following Stack expression it returns a value of type Integer: 10
.
> day(date(2022, 9, 10))
10
When used as an expression in text, prepend it with an @
:
> "... @day(date(2022, 9, 10)) ..."
"10"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "day(date(2022, 9, 10))",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 10 = result
10
iex> Expression.evaluate_as_string!(
...> "@day(date(2022, 9, 10))",
...> %{},
...> Expression.Callbacks.Standard
...> )
"10"
example-2
Example 2:
Getting today's day of the month
When used in the following Stack expression it returns a value of type Integer: 30
.
> day(now())
30
When used as an expression in text, prepend it with an @
:
> "... @day(now()) ..."
"30"
..$> import ExUnit.Assertions
..$> result = Expression.evaluate_block!(
...> "day(now())",
...> %{},
...> Expression.Callbacks.Standard
...> )
..$> assert 30 = result
30
..$> Expression.evaluate_as_string!(
...> "@day(now())",
...> %{},
...> Expression.Callbacks.Standard
...> )
"30"
edate(ctx, date, months)
Moves a date by the given number of months
example-1
Example 1:
Move the date in a date object by 1 month
When used in the following Stack expression it returns a value of type DateTime: ~U[2022-02-01 00:00:00Z]
when used with the following context:
%{right_now: ~U[2022-01-01 00:00:00Z]}
> edate(right_now, 1)
~U[2022-02-01 00:00:00Z]
When used as an expression in text, prepend it with an @
:
> "... @edate(right_now, 1) ..."
"2022-02-01T00:00:00Z"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "edate(right_now, 1)",
...> %{right_now: ~U[2022-01-01 00:00:00Z]},
...> Expression.Callbacks.Standard
...> )
iex> assert ~U[2022-02-01 00:00:00Z] = result
~U[2022-02-01 00:00:00Z]
iex> Expression.evaluate_as_string!(
...> "@edate(right_now, 1)",
...> %{right_now: ~U[2022-01-01 00:00:00Z]},
...> Expression.Callbacks.Standard
...> )
"2022-02-01T00:00:00Z"
example-2
Example 2:
Move the date store in a piece of text by 1 month
When used in the following Stack expression it returns a value of type Date: ~D[2022-11-10]
.
> edate("2022-10-10", 1)
~D[2022-11-10]
When used as an expression in text, prepend it with an @
:
> "... @edate("2022-10-10", 1) ..."
"2022-11-10"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "edate(\"2022-10-10\", 1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert ~D[2022-11-10] = result
~D[2022-11-10]
iex> Expression.evaluate_as_string!(
...> "@edate(\"2022-10-10\", 1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"2022-11-10"
expression_docs()
Return a list of all functions annotated with @expression_docs
first_word(ctx, binary)
Returns the first word in the given text - equivalent to WORD(text, 1)
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "foo"
.
> first_word("foo bar baz")
"foo"
When used as an expression in text, prepend it with an @
:
> "... @first_word("foo bar baz") ..."
"foo"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "first_word(\"foo bar baz\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "foo" = result
"foo"
iex> Expression.evaluate_as_string!(
...> "@first_word(\"foo bar baz\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"foo"
fixed(ctx, number, precision)
Formats the given number in decimal format using a period and commas
> You have @fixed(contact.balance, 2) in your account
"You have 4.21 in your account"
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "4.21"
.
> fixed(4.209922, 2, false)
"4.21"
When used as an expression in text, prepend it with an @
:
> "... @fixed(4.209922, 2, false) ..."
"4.21"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "fixed(4.209922, 2, false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "4.21" = result
"4.21"
iex> Expression.evaluate_as_string!(
...> "@fixed(4.209922, 2, false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"4.21"
example-2
Example 2:
When used in the following Stack expression it returns a value of type String: "4,000.4242"
.
> fixed(4000.424242, 4, true)
"4,000.4242"
When used as an expression in text, prepend it with an @
:
> "... @fixed(4000.424242, 4, true) ..."
"4,000.4242"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "fixed(4000.424242, 4, true)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "4,000.4242" = result
"4,000.4242"
iex> Expression.evaluate_as_string!(
...> "@fixed(4000.424242, 4, true)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"4,000.4242"
example-3
Example 3:
When used in the following Stack expression it returns a value of type String: "3.80"
.
> fixed(3.7979, 2, false)
"3.80"
When used as an expression in text, prepend it with an @
:
> "... @fixed(3.7979, 2, false) ..."
"3.80"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "fixed(3.7979, 2, false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "3.80" = result
"3.80"
iex> Expression.evaluate_as_string!(
...> "@fixed(3.7979, 2, false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"3.80"
example-4
Example 4:
When used in the following Stack expression it returns a value of type String: "3.80"
.
> fixed(3.7979, 2)
"3.80"
When used as an expression in text, prepend it with an @
:
> "... @fixed(3.7979, 2) ..."
"3.80"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "fixed(3.7979, 2)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "3.80" = result
"3.80"
iex> Expression.evaluate_as_string!(
...> "@fixed(3.7979, 2)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"3.80"
fixed(ctx, number, precision, no_commas)
handle(module \\ __MODULE__, function_name, arguments, context)
has_all_words(ctx, haystack, words)
Tests whether all the words are contained in text
The words can be in any order and may appear more than once.
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_all_words("the quick brown FOX", "the fox")
true
When used as an expression in text, prepend it with an @
:
> "... @has_all_words("the quick brown FOX", "the fox") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_all_words(\"the quick brown FOX\", \"the fox\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_all_words(\"the quick brown FOX\", \"the fox\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_all_words("the quick brown FOX", "red fox")
false
When used as an expression in text, prepend it with an @
:
> "... @has_all_words("the quick brown FOX", "red fox") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_all_words(\"the quick brown FOX\", \"red fox\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_all_words(\"the quick brown FOX\", \"red fox\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_any_word(ctx, haystack, words)
Tests whether any of the words are contained in the text
Only one of the words needs to match and it may appear more than once.
example-1
Example 1:
When used in the following Stack expression it returns a complex Boolean type of default value:
true
with the following fields:
- match of type String .
> has_any_word("The Quick Brown Fox", "fox quick")
%{"__value__" => true, "match" => "Quick Fox"}
When used as an expression in text, prepend it with an @
:
> "... @has_any_word("The Quick Brown Fox", "fox quick") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_any_word(\"The Quick Brown Fox\", \"fox quick\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert %{"__value__" => true, "match" => "Quick Fox"} = result
%{"__value__" => true, "match" => "Quick Fox"}
iex> Expression.evaluate_as_string!(
...> "@has_any_word(\"The Quick Brown Fox\", \"fox quick\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a complex Boolean type of default value:
false
with the following fields:
- match of type Null .
> has_any_word("The Quick Brown Fox", "yellow")
%{"__value__" => false, "match" => nil}
When used as an expression in text, prepend it with an @
:
> "... @has_any_word("The Quick Brown Fox", "yellow") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_any_word(\"The Quick Brown Fox\", \"yellow\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert %{"__value__" => false, "match" => nil} = result
%{"__value__" => false, "match" => nil}
iex> Expression.evaluate_as_string!(
...> "@has_any_word(\"The Quick Brown Fox\", \"yellow\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_beginning(ctx, text, beginning)
Tests whether text starts with beginning
Both text values are trimmed of surrounding whitespace, but otherwise matching is strict without any tokenization.
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_beginning("The Quick Brown", "the quick")
true
When used as an expression in text, prepend it with an @
:
> "... @has_beginning("The Quick Brown", "the quick") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_beginning(\"The Quick Brown\", \"the quick\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_beginning(\"The Quick Brown\", \"the quick\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_beginning("The Quick Brown", "the quick")
false
When used as an expression in text, prepend it with an @
:
> "... @has_beginning("The Quick Brown", "the quick") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_beginning(\"The Quick Brown\", \"the quick\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_beginning(\"The Quick Brown\", \"the quick\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_beginning("The Quick Brown", "quick brown")
false
When used as an expression in text, prepend it with an @
:
> "... @has_beginning("The Quick Brown", "quick brown") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_beginning(\"The Quick Brown\", \"quick brown\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_beginning(\"The Quick Brown\", \"quick brown\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_date(ctx, expression)
Tests whether expression
contains a date formatted according to our environment
This is very naively implemented with a regular expression.
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_date("the date is 15/01/2017")
true
When used as an expression in text, prepend it with an @
:
> "... @has_date("the date is 15/01/2017") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_date(\"the date is 15/01/2017\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_date(\"the date is 15/01/2017\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_date("there is no date here, just a year 2017")
false
When used as an expression in text, prepend it with an @
:
> "... @has_date("there is no date here, just a year 2017") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_date(\"there is no date here, just a year 2017\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_date(\"there is no date here, just a year 2017\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_date_eq(ctx, expression, date_string)
Tests whether expression
is a date equal to date_string
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_date_eq("the date is 15/01/2017", "2017-01-15")
true
When used as an expression in text, prepend it with an @
:
> "... @has_date_eq("the date is 15/01/2017", "2017-01-15") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_date_eq(\"the date is 15/01/2017\", \"2017-01-15\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_date_eq(\"the date is 15/01/2017\", \"2017-01-15\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_date_eq("there is no date here, just a year 2017", "2017-01-15")
false
When used as an expression in text, prepend it with an @
:
> "... @has_date_eq("there is no date here, just a year 2017", "2017-01-15") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_date_eq(\"there is no date here, just a year 2017\", \"2017-01-15\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_date_eq(\"there is no date here, just a year 2017\", \"2017-01-15\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_date_gt(ctx, expression, date_string)
Tests whether expression
is a date after the date date_string
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_date_gt("the date is 15/01/2017", "2017-01-01")
true
When used as an expression in text, prepend it with an @
:
> "... @has_date_gt("the date is 15/01/2017", "2017-01-01") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_date_gt(\"the date is 15/01/2017\", \"2017-01-01\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_date_gt(\"the date is 15/01/2017\", \"2017-01-01\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_date_gt("the date is 15/01/2017", "2017-03-15")
false
When used as an expression in text, prepend it with an @
:
> "... @has_date_gt("the date is 15/01/2017", "2017-03-15") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_date_gt(\"the date is 15/01/2017\", \"2017-03-15\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_date_gt(\"the date is 15/01/2017\", \"2017-03-15\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_date_lt(ctx, expression, date_string)
Tests whether expression
contains a date before the date date_string
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_date_lt("the date is 15/01/2017", "2017-06-01")
true
When used as an expression in text, prepend it with an @
:
> "... @has_date_lt("the date is 15/01/2017", "2017-06-01") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_date_lt(\"the date is 15/01/2017\", \"2017-06-01\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_date_lt(\"the date is 15/01/2017\", \"2017-06-01\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_date_lt("the date is 15/01/2021", "2017-03-15")
false
When used as an expression in text, prepend it with an @
:
> "... @has_date_lt("the date is 15/01/2021", "2017-03-15") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_date_lt(\"the date is 15/01/2021\", \"2017-03-15\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_date_lt(\"the date is 15/01/2021\", \"2017-03-15\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_email(ctx, expression)
Tests whether an email is contained in text
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_email("my email is foo1@bar.com, please respond")
true
When used as an expression in text, prepend it with an @
:
> "... @has_email("my email is foo1@bar.com, please respond") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_email(\"my email is foo1@bar.com, please respond\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_email(\"my email is foo1@bar.com, please respond\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_email("i'm not sharing my email")
false
When used as an expression in text, prepend it with an @
:
> "... @has_email("i'm not sharing my email") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_email(\"i'm not sharing my email\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_email(\"i'm not sharing my email\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_group(ctx, groups, uuid)
Returns whether the contact is part of group with the passed in UUID
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
when used with the following context:
%{"contact" => %{"groups" => [%{"uuid" => "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d"}]}}
> has_group(contact.groups, "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d")
true
When used as an expression in text, prepend it with an @
:
> "... @has_group(contact.groups, "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_group(contact.groups, \"b7cf0d83-f1c9-411c-96fd-c511a4cfa86d\")",
...> %{"contact" => %{"groups" => [%{"uuid" => "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d"}]}},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_group(contact.groups, \"b7cf0d83-f1c9-411c-96fd-c511a4cfa86d\")",
...> %{"contact" => %{"groups" => [%{"uuid" => "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d"}]}},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: false
when used with the following context:
%{"contact" => %{"groups" => [%{"uuid" => "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d"}]}}
> has_group(contact.groups, "00000000-0000-0000-0000-000000000000")
false
When used as an expression in text, prepend it with an @
:
> "... @has_group(contact.groups, "00000000-0000-0000-0000-000000000000") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_group(contact.groups, \"00000000-0000-0000-0000-000000000000\")",
...> %{"contact" => %{"groups" => [%{"uuid" => "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d"}]}},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_group(contact.groups, \"00000000-0000-0000-0000-000000000000\")",
...> %{"contact" => %{"groups" => [%{"uuid" => "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d"}]}},
...> Expression.Callbacks.Standard
...> )
"false"
has_number(ctx, expression)
Tests whether expression
contains a number
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number("the number is 42 and 5")
true
When used as an expression in text, prepend it with an @
:
> "... @has_number("the number is 42 and 5") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number(\"the number is 42 and 5\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number(\"the number is 42 and 5\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number("العدد ٤٢")
true
When used as an expression in text, prepend it with an @
:
> "... @has_number("العدد ٤٢") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number(\"العدد ٤٢\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number(\"العدد ٤٢\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number("٠.٥")
true
When used as an expression in text, prepend it with an @
:
> "... @has_number("٠.٥") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number(\"٠.٥\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number(\"٠.٥\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-4
Example 4:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number("0.6")
true
When used as an expression in text, prepend it with an @
:
> "... @has_number("0.6") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number(\"0.6\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number(\"0.6\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
has_number_eq(ctx, expression, float)
Tests whether expression
contains a number equal to the value
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_eq("the number is 42", 42)
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_eq("the number is 42", 42) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_eq(\"the number is 42\", 42)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_eq(\"the number is 42\", 42)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_eq("the number is 42", 42.0)
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_eq("the number is 42", 42.0) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_eq(\"the number is 42\", 42.0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_eq(\"the number is 42\", 42.0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_eq("the number is 42", "42")
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_eq("the number is 42", "42") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_eq(\"the number is 42\", \"42\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_eq(\"the number is 42\", \"42\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-4
Example 4:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_eq("the number is 42.0", "42")
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_eq("the number is 42.0", "42") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_eq(\"the number is 42.0\", \"42\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_eq(\"the number is 42.0\", \"42\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-5
Example 5:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_eq("the number is 40", "42")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_eq("the number is 40", "42") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_eq(\"the number is 40\", \"42\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_eq(\"the number is 40\", \"42\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-6
Example 6:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_eq("the number is 40", "foo")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_eq("the number is 40", "foo") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_eq(\"the number is 40\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_eq(\"the number is 40\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-7
Example 7:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_eq("four hundred", "foo")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_eq("four hundred", "foo") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_eq(\"four hundred\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_eq(\"four hundred\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_number_gt(ctx, expression, float)
Tests whether expression
contains a number greater than min
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_gt("the number is 42", 40)
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_gt("the number is 42", 40) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gt(\"the number is 42\", 40)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_gt(\"the number is 42\", 40)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_gt("the number is 42", 40.0)
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_gt("the number is 42", 40.0) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gt(\"the number is 42\", 40.0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_gt(\"the number is 42\", 40.0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_gt("the number is 42", "40")
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_gt("the number is 42", "40") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gt(\"the number is 42\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_gt(\"the number is 42\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-4
Example 4:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_gt("the number is 42.0", "40")
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_gt("the number is 42.0", "40") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gt(\"the number is 42.0\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_gt(\"the number is 42.0\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-5
Example 5:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_gt("the number is 40", "40")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_gt("the number is 40", "40") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gt(\"the number is 40\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_gt(\"the number is 40\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-6
Example 6:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_gt("the number is 40", "foo")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_gt("the number is 40", "foo") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gt(\"the number is 40\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_gt(\"the number is 40\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-7
Example 7:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_gt("four hundred", "foo")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_gt("four hundred", "foo") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gt(\"four hundred\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_gt(\"four hundred\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_number_gte(ctx, expression, float)
Tests whether expression
contains a number greater than or equal to min
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_gte("the number is 42", 42)
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_gte("the number is 42", 42) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gte(\"the number is 42\", 42)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_gte(\"the number is 42\", 42)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_gte("the number is 42", 42.0)
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_gte("the number is 42", 42.0) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gte(\"the number is 42\", 42.0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_gte(\"the number is 42\", 42.0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_gte("the number is 42", "42")
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_gte("the number is 42", "42") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gte(\"the number is 42\", \"42\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_gte(\"the number is 42\", \"42\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-4
Example 4:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_gte("the number is 42.0", "45")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_gte("the number is 42.0", "45") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gte(\"the number is 42.0\", \"45\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_gte(\"the number is 42.0\", \"45\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-5
Example 5:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_gte("the number is 40", "45")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_gte("the number is 40", "45") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gte(\"the number is 40\", \"45\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_gte(\"the number is 40\", \"45\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-6
Example 6:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_gte("the number is 40", "foo")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_gte("the number is 40", "foo") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gte(\"the number is 40\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_gte(\"the number is 40\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-7
Example 7:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_gte("four hundred", "foo")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_gte("four hundred", "foo") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_gte(\"four hundred\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_gte(\"four hundred\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_number_lt(ctx, expression, float)
Tests whether expression
contains a number less than max
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_lt("the number is 42", 44)
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_lt("the number is 42", 44) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lt(\"the number is 42\", 44)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_lt(\"the number is 42\", 44)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_lt("the number is 42", 44.0)
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_lt("the number is 42", 44.0) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lt(\"the number is 42\", 44.0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_lt(\"the number is 42\", 44.0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_lt("the number is 42", "40")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_lt("the number is 42", "40") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lt(\"the number is 42\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_lt(\"the number is 42\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-4
Example 4:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_lt("the number is 42.0", "40")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_lt("the number is 42.0", "40") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lt(\"the number is 42.0\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_lt(\"the number is 42.0\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-5
Example 5:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_lt("the number is 40", "40")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_lt("the number is 40", "40") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lt(\"the number is 40\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_lt(\"the number is 40\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-6
Example 6:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_lt("the number is 40", "foo")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_lt("the number is 40", "foo") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lt(\"the number is 40\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_lt(\"the number is 40\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-7
Example 7:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_lt("four hundred", "foo")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_lt("four hundred", "foo") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lt(\"four hundred\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_lt(\"four hundred\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_number_lte(ctx, expression, float)
Tests whether expression
contains a number less than or equal to max
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_lte("the number is 42", 42)
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_lte("the number is 42", 42) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lte(\"the number is 42\", 42)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_lte(\"the number is 42\", 42)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_lte("the number is 42", 42.0)
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_lte("the number is 42", 42.0) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lte(\"the number is 42\", 42.0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_lte(\"the number is 42\", 42.0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_number_lte("the number is 42", "42")
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_lte("the number is 42", "42") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lte(\"the number is 42\", \"42\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_lte(\"the number is 42\", \"42\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-4
Example 4:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_lte("the number is 42.0", "40")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_lte("the number is 42.0", "40") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lte(\"the number is 42.0\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_lte(\"the number is 42.0\", \"40\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-5
Example 5:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_lte("the number is 40", "foo")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_lte("the number is 40", "foo") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lte(\"the number is 40\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_lte(\"the number is 40\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-6
Example 6:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_number_lte("four hundred", "foo")
false
When used as an expression in text, prepend it with an @
:
> "... @has_number_lte("four hundred", "foo") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lte(\"four hundred\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_number_lte(\"four hundred\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-7
Example 7:
When used in the following Stack expression it returns a value of type Boolean: true
when used with the following context:
%{"response" => 3}
> has_number_lte("@response", 5)
true
When used as an expression in text, prepend it with an @
:
> "... @has_number_lte("@response", 5) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_number_lte(\"@response\", 5)",
...> %{"response" => 3},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_number_lte(\"@response\", 5)",
...> %{"response" => 3},
...> Expression.Callbacks.Standard
...> )
"true"
has_only_phrase(ctx, expression, phrase)
Tests whether the text contains only phrase
The phrase must be the only text in the text to match
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_only_phrase("Quick Brown", "quick brown")
true
When used as an expression in text, prepend it with an @
:
> "... @has_only_phrase("Quick Brown", "quick brown") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_only_phrase(\"Quick Brown\", \"quick brown\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_only_phrase(\"Quick Brown\", \"quick brown\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_only_phrase("", "")
true
When used as an expression in text, prepend it with an @
:
> "... @has_only_phrase("", "") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_only_phrase(\"\", \"\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_only_phrase(\"\", \"\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_only_phrase("The Quick Brown Fox", "quick brown")
false
When used as an expression in text, prepend it with an @
:
> "... @has_only_phrase("The Quick Brown Fox", "quick brown") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_only_phrase(\"The Quick Brown Fox\", \"quick brown\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_only_phrase(\"The Quick Brown Fox\", \"quick brown\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_only_text(ctx, expression_one, expression_two)
Returns whether two text values are equal (case sensitive). In the case that they are, it will return the text as the match.
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_only_text("foo", "foo")
true
When used as an expression in text, prepend it with an @
:
> "... @has_only_text("foo", "foo") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_only_text(\"foo\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_only_text(\"foo\", \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_only_text("", "")
true
When used as an expression in text, prepend it with an @
:
> "... @has_only_text("", "") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_only_text(\"\", \"\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_only_text(\"\", \"\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_only_text("foo", "FOO")
false
When used as an expression in text, prepend it with an @
:
> "... @has_only_text("foo", "FOO") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_only_text(\"foo\", \"FOO\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_only_text(\"foo\", \"FOO\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_pattern(ctx, expression, pattern)
Tests whether expression
matches the regex pattern
Both text values are trimmed of surrounding whitespace and matching is case-insensitive.
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_pattern("Buy cheese please", "buy (\w+)")
true
When used as an expression in text, prepend it with an @
:
> "... @has_pattern("Buy cheese please", "buy (\w+)") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_pattern(\"Buy cheese please\", \"buy (\\w+)\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_pattern(\"Buy cheese please\", \"buy (\\w+)\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_pattern("Sell cheese please", "buy (\w+)")
false
When used as an expression in text, prepend it with an @
:
> "... @has_pattern("Sell cheese please", "buy (\w+)") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_pattern(\"Sell cheese please\", \"buy (\\w+)\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_pattern(\"Sell cheese please\", \"buy (\\w+)\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_phone(ctx, expression)
Tests whether expresssion
contains a phone number.
The optional country_code argument specifies the country to use for parsing.
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_phone("my number is +12067799294 thanks")
true
When used as an expression in text, prepend it with an @
:
> "... @has_phone("my number is +12067799294 thanks") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_phone(\"my number is +12067799294 thanks\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_phone(\"my number is +12067799294 thanks\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_phone("my number is 2067799294 thanks", "US")
true
When used as an expression in text, prepend it with an @
:
> "... @has_phone("my number is 2067799294 thanks", "US") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_phone(\"my number is 2067799294 thanks\", \"US\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_phone(\"my number is 2067799294 thanks\", \"US\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_phone("my number is 206 779 9294 thanks", "US")
true
When used as an expression in text, prepend it with an @
:
> "... @has_phone("my number is 206 779 9294 thanks", "US") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_phone(\"my number is 206 779 9294 thanks\", \"US\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_phone(\"my number is 206 779 9294 thanks\", \"US\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-4
Example 4:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_phone("my number is none of your business", "US")
false
When used as an expression in text, prepend it with an @
:
> "... @has_phone("my number is none of your business", "US") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_phone(\"my number is none of your business\", \"US\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_phone(\"my number is none of your business\", \"US\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
has_phone(ctx, expression, country_code)
has_phrase(ctx, expression, phrase)
Tests whether phrase is contained in expression
The words in the test phrase must appear in the same order with no other words in between.
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_phrase("the quick brown fox", "brown fox")
true
When used as an expression in text, prepend it with an @
:
> "... @has_phrase("the quick brown fox", "brown fox") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_phrase(\"the quick brown fox\", \"brown fox\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_phrase(\"the quick brown fox\", \"brown fox\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_phrase("the quick brown fox", "quick fox")
false
When used as an expression in text, prepend it with an @
:
> "... @has_phrase("the quick brown fox", "quick fox") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_phrase(\"the quick brown fox\", \"quick fox\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_phrase(\"the quick brown fox\", \"quick fox\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_phrase("the quick brown fox", "")
true
When used as an expression in text, prepend it with an @
:
> "... @has_phrase("the quick brown fox", "") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_phrase(\"the quick brown fox\", \"\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_phrase(\"the quick brown fox\", \"\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
has_text(ctx, expression)
Tests whether there the expression
has any characters in it
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_text("quick brown")
true
When used as an expression in text, prepend it with an @
:
> "... @has_text("quick brown") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_text(\"quick brown\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_text(\"quick brown\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_text("")
false
When used as an expression in text, prepend it with an @
:
> "... @has_text("") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_text(\"\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_text(\"\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_text("
> ")
false
When used as an expression in text, prepend it with an @
:
> "... @has_text("
") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_text(\" \n\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_text(\" \n\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-4
Example 4:
When used in the following Stack expression it returns a value of type Boolean: true
.
> has_text(123)
true
When used as an expression in text, prepend it with an @
:
> "... @has_text(123) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_text(123)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@has_text(123)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
has_time(ctx, expression)
Tests whether expression
contains a time.
example-1
Example 1:
When used in the following Stack expression it returns a complex Boolean type of default value:
true
with the following fields:
- match of type Time .
> has_time("the time is 10:30")
%{"__value__" => true, "match" => ~T[10:30:00]}
When used as an expression in text, prepend it with an @
:
> "... @has_time("the time is 10:30") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_time(\"the time is 10:30\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert %{"__value__" => true, "match" => ~T[10:30:00]} = result
%{"__value__" => true, "match" => ~T[10:30:00]}
iex> Expression.evaluate_as_string!(
...> "@has_time(\"the time is 10:30\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a complex Boolean type of default value:
true
with the following fields:
- match of type Time .
> has_time("the time is 10:00 pm")
%{"__value__" => true, "match" => ~T[10:00:00]}
When used as an expression in text, prepend it with an @
:
> "... @has_time("the time is 10:00 pm") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_time(\"the time is 10:00 pm\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert %{"__value__" => true, "match" => ~T[10:00:00]} = result
%{"__value__" => true, "match" => ~T[10:00:00]}
iex> Expression.evaluate_as_string!(
...> "@has_time(\"the time is 10:00 pm\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-3
Example 3:
When used in the following Stack expression it returns a complex Boolean type of default value:
true
with the following fields:
- match of type Time .
> has_time("the time is 10:30:45")
%{"__value__" => true, "match" => ~T[10:30:45]}
When used as an expression in text, prepend it with an @
:
> "... @has_time("the time is 10:30:45") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_time(\"the time is 10:30:45\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert %{"__value__" => true, "match" => ~T[10:30:45]} = result
%{"__value__" => true, "match" => ~T[10:30:45]}
iex> Expression.evaluate_as_string!(
...> "@has_time(\"the time is 10:30:45\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-4
Example 4:
When used in the following Stack expression it returns a value of type Boolean: false
.
> has_time("there is no time here, just the number 25")
false
When used as an expression in text, prepend it with an @
:
> "... @has_time("there is no time here, just the number 25") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "has_time(\"there is no time here, just the number 25\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@has_time(\"there is no time here, just the number 25\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
hour(ctx, date)
Returns only the hour of a datetime (0 to 23)
example-1
Example 1:
Get the current hour
When used in the following Stack expression it returns a value of type Integer: 17
.
> hour(now())
17
When used as an expression in text, prepend it with an @
:
> "... @hour(now()) ..."
"17"
..$> import ExUnit.Assertions
..$> result = Expression.evaluate_block!(
...> "hour(now())",
...> %{},
...> Expression.Callbacks.Standard
...> )
..$> assert 17 = result
17
..$> Expression.evaluate_as_string!(
...> "@hour(now())",
...> %{},
...> Expression.Callbacks.Standard
...> )
"17"
if_(ctx, condition, yes, no)
Returns one value if the condition evaluates to true
, and another value if it evaluates to false
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "Yes"
.
> if true do
> "Yes"
> else
> "No"
> end
>
"Yes"
When used as an expression in text, prepend it with an @
:
> "... @if(true, "Yes", "No") ..."
"Yes"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "if(true, \"Yes\", \"No\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "Yes" = result
"Yes"
iex> Expression.evaluate_as_string!(
...> "@if(true, \"Yes\", \"No\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"Yes"
example-2
Example 2:
When used in the following Stack expression it returns a value of type String: "No"
.
> # Shorthand
> if(false, do: "Yes", else: "No")
"No"
When used as an expression in text, prepend it with an @
:
> "... @if(false, "Yes", "No") ..."
"No"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "if(false, \"Yes\", \"No\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "No" = result
"No"
iex> Expression.evaluate_as_string!(
...> "@if(false, \"Yes\", \"No\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"No"
isbool(ctx, var)
Returns true
if the argument is a boolean.
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> isbool(true)
true
When used as an expression in text, prepend it with an @
:
> "... @isbool(true) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "isbool(true)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@isbool(true)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: true
.
> isbool(false)
true
When used as an expression in text, prepend it with an @
:
> "... @isbool(false) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "isbool(false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@isbool(false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: false
.
> isbool(1)
false
When used as an expression in text, prepend it with an @
:
> "... @isbool(1) ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "isbool(1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@isbool(1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-4
Example 4:
When used in the following Stack expression it returns a value of type Boolean: false
.
> isbool(0)
false
When used as an expression in text, prepend it with an @
:
> "... @isbool(0) ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "isbool(0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@isbool(0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-5
Example 5:
When used in the following Stack expression it returns a value of type Boolean: false
.
> isbool("true")
false
When used as an expression in text, prepend it with an @
:
> "... @isbool("true") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "isbool(\"true\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@isbool(\"true\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-6
Example 6:
When used in the following Stack expression it returns a value of type Boolean: false
.
> isbool("false")
false
When used as an expression in text, prepend it with an @
:
> "... @isbool("false") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "isbool(\"false\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@isbool(\"false\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
isnumber(ctx, var)
Returns true
if the argument is a number.
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> isnumber(1)
true
When used as an expression in text, prepend it with an @
:
> "... @isnumber(1) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "isnumber(1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@isnumber(1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: true
.
> isnumber(1.0)
true
When used as an expression in text, prepend it with an @
:
> "... @isnumber(1.0) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "isnumber(1.0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@isnumber(1.0)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: true
.
> isnumber("1.0")
true
When used as an expression in text, prepend it with an @
:
> "... @isnumber("1.0") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "isnumber(\"1.0\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@isnumber(\"1.0\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-4
Example 4:
When used in the following Stack expression it returns a value of type Boolean: false
.
> isnumber("a")
false
When used as an expression in text, prepend it with an @
:
> "... @isnumber("a") ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "isnumber(\"a\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@isnumber(\"a\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
isstring(ctx, binary)
Returns true
if the argument is a string.
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> isstring("hello")
true
When used as an expression in text, prepend it with an @
:
> "... @isstring("hello") ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "isstring(\"hello\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@isstring(\"hello\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Boolean: false
.
> isstring(false)
false
When used as an expression in text, prepend it with an @
:
> "... @isstring(false) ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "isstring(false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@isstring(false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: false
.
> isstring(1)
false
When used as an expression in text, prepend it with an @
:
> "... @isstring(1) ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "isstring(1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@isstring(1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
left(ctx, binary, size)
Returns the first characters in a text string. This is Unicode safe.
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "foob"
.
> left("foobar", 4)
"foob"
When used as an expression in text, prepend it with an @
:
> "... @left("foobar", 4) ..."
"foob"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "left(\"foobar\", 4)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "foob" = result
"foob"
iex> Expression.evaluate_as_string!(
...> "@left(\"foobar\", 4)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"foob"
example-2
Example 2:
When used in the following Stack expression it returns a value of type String: "Умерла Мадлен Олбрай"
.
> left("Умерла Мадлен Олбрайт - первая женщина на посту главы Госдепа США", 20)
"Умерла Мадлен Олбрай"
When used as an expression in text, prepend it with an @
:
> "... @left("Умерла Мадлен Олбрайт - первая женщина на посту главы Госдепа США", 20) ..."
"Умерла Мадлен Олбрай"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "left(\"Умерла Мадлен Олбрайт - первая женщина на посту главы Госдепа США\", 20)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "Умерла Мадлен Олбрай" = result
"Умерла Мадлен Олбрай"
iex> Expression.evaluate_as_string!(
...> "@left(\"Умерла Мадлен Олбрайт - первая женщина на посту главы Госдепа США\", 20)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"Умерла Мадлен Олбрай"
len(ctx, binary)
Returns the number of characters in a text string
example-1
Example 1:
When used in the following Stack expression it returns a value of type Integer: 3
.
> len("foo")
3
When used as an expression in text, prepend it with an @
:
> "... @len("foo") ..."
"3"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "len(\"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 3 = result
3
iex> Expression.evaluate_as_string!(
...> "@len(\"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"3"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Integer: 3
.
> len("zoë")
3
When used as an expression in text, prepend it with an @
:
> "... @len("zoë") ..."
"3"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "len(\"zoë\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 3 = result
3
iex> Expression.evaluate_as_string!(
...> "@len(\"zoë\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"3"
lower(ctx, binary)
Converts a text string to lowercase
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "foo bar"
.
> lower("Foo Bar")
"foo bar"
When used as an expression in text, prepend it with an @
:
> "... @lower("Foo Bar") ..."
"foo bar"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "lower(\"Foo Bar\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "foo bar" = result
"foo bar"
iex> Expression.evaluate_as_string!(
...> "@lower(\"Foo Bar\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"foo bar"
map(ctx, enumerable, mapper)
map over a list of items and apply the mapper function to every item, returning the result.
example-1
Example 1:
Map over the range of numbers, create a date in January for every number
When used in the following Stack expression it returns a value of type List with values Date, Date, Date: [~D[2022-01-01], ~D[2022-01-02], ~D[2022-01-03]]
.
> map(1..3, &date(2022, 1, &1))
[~D[2022-01-01], ~D[2022-01-02], ~D[2022-01-03]]
When used as an expression in text, prepend it with an @
:
> "... @map(1..3, &date(2022, 1, &1)) ..."
"2022-01-012022-01-022022-01-03"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "map(1..3, &date(2022, 1, &1))",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert [~D[2022-01-01], ~D[2022-01-02], ~D[2022-01-03]] = result
[~D[2022-01-01], ~D[2022-01-02], ~D[2022-01-03]]
iex> Expression.evaluate_as_string!(
...> "@map(1..3, &date(2022, 1, &1))",
...> %{},
...> Expression.Callbacks.Standard
...> )
"2022-01-012022-01-022022-01-03"
example-2
Example 2:
Map over the range of numbers, multiple each by itself and return the result
When used in the following Stack expression it returns a value of type List with values Integer, Integer, Integer: [1, 4, 9]
.
> map(1..3, &(&1 * &1))
[1, 4, 9]
When used as an expression in text, prepend it with an @
:
> "... @map(1..3, &(&1 * &1)) ..."
"149"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "map(1..3, &(&1 * &1))",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert [1, 4, 9] = result
[1, 4, 9]
iex> Expression.evaluate_as_string!(
...> "@map(1..3, &(&1 * &1))",
...> %{},
...> Expression.Callbacks.Standard
...> )
"149"
max_vargs(ctx, arguments)
Returns the maximum value of all arguments
example-1
Example 1:
When used in the following Stack expression it returns a value of type Integer: 3
.
> max(1, 2, 3)
3
When used as an expression in text, prepend it with an @
:
> "... @max(1, 2, 3) ..."
"3"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "max(1, 2, 3)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 3 = result
3
iex> Expression.evaluate_as_string!(
...> "@max(1, 2, 3)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"3"
min_vargs(ctx, arguments)
Returns the minimum value of all arguments
example-1
Example 1:
When used in the following Stack expression it returns a value of type Integer: 1
.
> min(1, 2, 3)
1
When used as an expression in text, prepend it with an @
:
> "... @min(1, 2, 3) ..."
"1"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "min(1, 2, 3)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 1 = result
1
iex> Expression.evaluate_as_string!(
...> "@min(1, 2, 3)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"1"
minute(ctx, date)
Returns only the minute of a datetime (0 to 59)
example-1
Example 1:
Get the current minute
When used in the following Stack expression it returns a value of type Integer: 13
.
> minute(now())
13
When used as an expression in text, prepend it with an @
:
> "... @minute(now()) ..."
"13"
..$> import ExUnit.Assertions
..$> result = Expression.evaluate_block!(
...> "minute(now())",
...> %{},
...> Expression.Callbacks.Standard
...> )
..$> assert 13 = result
13
..$> Expression.evaluate_as_string!(
...> "@minute(now())",
...> %{},
...> Expression.Callbacks.Standard
...> )
"13"
month(ctx, date)
Returns only the month of a date (1 to 12)
example-1
Example 1:
Get the current month
When used in the following Stack expression it returns a value of type Integer: 5
.
> month(now())
5
When used as an expression in text, prepend it with an @
:
> "... @month(now()) ..."
"5"
..$> import ExUnit.Assertions
..$> result = Expression.evaluate_block!(
...> "month(now())",
...> %{},
...> Expression.Callbacks.Standard
...> )
..$> assert 5 = result
5
..$> Expression.evaluate_as_string!(
...> "@month(now())",
...> %{},
...> Expression.Callbacks.Standard
...> )
"5"
not_(ctx, argument)
Returns false
if the argument supplied evaluates to truth-y
example-1
Example 1:
When used in the following Stack expression it returns a value of type Boolean: true
.
> not(false)
true
When used as an expression in text, prepend it with an @
:
> "... @not(false) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "not(false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@not(false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
now(ctx)
Returns the current date time as UTC
It is currently @NOW()
example-1
Example 1:
return the current timestamp as a DateTime value
When used in the following Stack expression it returns a value of type DateTime: ~U[2023-05-30 17:13:08.134806Z]
.
> now()
~U[2023-05-30 17:13:08.134806Z]
When used as an expression in text, prepend it with an @
:
> "... @now() ..."
"2023-05-30T17:13:08.134806Z"
..$> import ExUnit.Assertions
..$> result = Expression.evaluate_block!(
...> "now()",
...> %{},
...> Expression.Callbacks.Standard
...> )
..$> assert ~U[2023-05-30 17:13:08.134806Z] = result
~U[2023-05-30 17:13:08.134806Z]
..$> Expression.evaluate_as_string!(
...> "@now()",
...> %{},
...> Expression.Callbacks.Standard
...> )
"2023-05-30T17:13:08.134806Z"
example-2
Example 2:
return the current datetime and format it using
datevalue
When used in the following Stack expression it returns a complex String type of default value:
"2023-05-30"
with the following fields:
- date of type DateTime .
> datevalue(now(), "%Y-%m-%d")
%{"__value__" => "2023-05-30", "date" => ~U[2023-05-30 17:13:08.176192Z]}
When used as an expression in text, prepend it with an @
:
> "... @datevalue(now(), "%Y-%m-%d") ..."
"2023-05-30"
..$> import ExUnit.Assertions
..$> result = Expression.evaluate_block!(
...> "datevalue(now(), \"%Y-%m-%d\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
..$> assert %{"__value__" => "2023-05-30", "date" => ~U[2023-05-30 17:13:08.176192Z]} = result
%{"__value__" => "2023-05-30", "date" => ~U[2023-05-30 17:13:08.176192Z]}
..$> Expression.evaluate_as_string!(
...> "@datevalue(now(), \"%Y-%m-%d\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"2023-05-30"
or_vargs(ctx, arguments)
Returns true
if any argument is true
.
Returns the first truthy value found or otherwise false.
Accepts any amount of arguments for testing truthiness.
example-1
Example 1:
Return true if any of the values are true
When used in the following Stack expression it returns a value of type Boolean: true
.
> true or false
true
When used as an expression in text, prepend it with an @
:
> "... @or(true, false) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "or(true, false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@or(true, false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-2
Example 2:
Return the first value that is truthy
When used in the following Stack expression it returns a value of type String: "foo"
.
> false or "foo"
"foo"
When used as an expression in text, prepend it with an @
:
> "... @or(false, "foo") ..."
"foo"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "or(false, \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "foo" = result
"foo"
iex> Expression.evaluate_as_string!(
...> "@or(false, \"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"foo"
example-3
Example 3:
When used in the following Stack expression it returns a value of type Boolean: true
.
> true or true
true
When used as an expression in text, prepend it with an @
:
> "... @or(true, true) ..."
"true"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "or(true, true)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert true = result
true
iex> Expression.evaluate_as_string!(
...> "@or(true, true)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"true"
example-4
Example 4:
When used in the following Stack expression it returns a value of type Boolean: false
.
> false or false
false
When used as an expression in text, prepend it with an @
:
> "... @or(false, false) ..."
"false"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "or(false, false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> refute result
false
iex> Expression.evaluate_as_string!(
...> "@or(false, false)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"false"
parse_float(number)
percent(ctx, float)
Formats a number as a percentage
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "20%"
.
> percent(2/10)
"20%"
When used as an expression in text, prepend it with an @
:
> "... @percent(2/10) ..."
"20%"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "percent(2/10)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "20%" = result
"20%"
iex> Expression.evaluate_as_string!(
...> "@percent(2/10)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"20%"
example-2
Example 2:
When used in the following Stack expression it returns a value of type String: "20%"
.
> percent(0.2)
"20%"
When used as an expression in text, prepend it with an @
:
> "... @percent(0.2) ..."
"20%"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "percent(0.2)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "20%" = result
"20%"
iex> Expression.evaluate_as_string!(
...> "@percent(0.2)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"20%"
example-3
Example 3:
When used in the following Stack expression it returns a value of type String: "20%"
when used with the following context:
%{"d" => "0.2"}
> percent(d)
"20%"
When used as an expression in text, prepend it with an @
:
> "... @percent(d) ..."
"20%"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "percent(d)",
...> %{"d" => "0.2"},
...> Expression.Callbacks.Standard
...> )
iex> assert "20%" = result
"20%"
iex> Expression.evaluate_as_string!(
...> "@percent(d)",
...> %{"d" => "0.2"},
...> Expression.Callbacks.Standard
...> )
"20%"
power(ctx, a, b)
Returns the result of a number raised to a power - equivalent to the ^ operator
example-1
Example 1:
When used in the following Stack expression it returns a value of type Float: 8.0
.
> power(2, 3)
8.0
When used as an expression in text, prepend it with an @
:
> "... @power(2, 3) ..."
"8.0"
..$> import ExUnit.Assertions
..$> result = Expression.evaluate_block!(
...> "power(2, 3)",
...> %{},
...> Expression.Callbacks.Standard
...> )
..$> assert 8.0 = result
8.0
..$> Expression.evaluate_as_string!(
...> "@power(2, 3)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"8.0"
proper(ctx, binary)
Capitalizes the first letter of every word in a text string
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "Foo Bar"
.
> proper("foo bar")
"Foo Bar"
When used as an expression in text, prepend it with an @
:
> "... @proper("foo bar") ..."
"Foo Bar"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "proper(\"foo bar\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "Foo Bar" = result
"Foo Bar"
iex> Expression.evaluate_as_string!(
...> "@proper(\"foo bar\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"Foo Bar"
read_digits(ctx, binary)
Formats digits in text for reading in TTS
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "plus two seven one"
.
> read_digits("+271")
"plus two seven one"
When used as an expression in text, prepend it with an @
:
> "... @read_digits("+271") ..."
"plus two seven one"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "read_digits(\"+271\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "plus two seven one" = result
"plus two seven one"
iex> Expression.evaluate_as_string!(
...> "@read_digits(\"+271\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"plus two seven one"
rem(ctx, integer1, integer2)
Return the division remainder of two integers.
example-1
Example 1:
When used in the following Stack expression it returns a value of type Integer: 0
.
> rem(4, 2)
0
When used as an expression in text, prepend it with an @
:
> "... @rem(4, 2) ..."
"0"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "rem(4, 2)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 0 = result
0
iex> Expression.evaluate_as_string!(
...> "@rem(4, 2)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"0"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Integer: 1
.
> rem(85, 3)
1
When used as an expression in text, prepend it with an @
:
> "... @rem(85, 3) ..."
"1"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "rem(85, 3)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 1 = result
1
iex> Expression.evaluate_as_string!(
...> "@rem(85, 3)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"1"
remove_first_word(ctx, binary)
Removes the first word from the given text. The remaining text will be unchanged
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "bar"
.
> remove_first_word("foo bar")
"bar"
When used as an expression in text, prepend it with an @
:
> "... @remove_first_word("foo bar") ..."
"bar"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "remove_first_word(\"foo bar\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "bar" = result
"bar"
iex> Expression.evaluate_as_string!(
...> "@remove_first_word(\"foo bar\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"bar"
example-2
Example 2:
When used in the following Stack expression it returns a value of type String: "bar"
.
> remove_first_word("foo-bar", "-")
"bar"
When used as an expression in text, prepend it with an @
:
> "... @remove_first_word("foo-bar", "-") ..."
"bar"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "remove_first_word(\"foo-bar\", \"-\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "bar" = result
"bar"
iex> Expression.evaluate_as_string!(
...> "@remove_first_word(\"foo-bar\", \"-\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"bar"
remove_first_word(ctx, binary, separator)
rept(ctx, value, amount)
Repeats text a given number of times
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "**********"
.
> rept("*", 10)
"**********"
When used as an expression in text, prepend it with an @
:
> "... @rept("*", 10) ..."
"**********"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "rept(\"*\", 10)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "**********" = result
"**********"
iex> Expression.evaluate_as_string!(
...> "@rept(\"*\", 10)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"**********"
right(ctx, binary, size)
Returns the last characters in a text string. This is Unicode safe.
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "ing"
.
> right("testing", 3)
"ing"
When used as an expression in text, prepend it with an @
:
> "... @right("testing", 3) ..."
"ing"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "right(\"testing\", 3)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "ing" = result
"ing"
iex> Expression.evaluate_as_string!(
...> "@right(\"testing\", 3)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"ing"
example-2
Example 2:
When used in the following Stack expression it returns a value of type String: "ту главы Госдепа США"
.
> right("Умерла Мадлен Олбрайт - первая женщина на посту главы Госдепа США", 20)
"ту главы Госдепа США"
When used as an expression in text, prepend it with an @
:
> "... @right("Умерла Мадлен Олбрайт - первая женщина на посту главы Госдепа США", 20) ..."
"ту главы Госдепа США"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "right(\"Умерла Мадлен Олбрайт - первая женщина на посту главы Госдепа США\", 20)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "ту главы Госдепа США" = result
"ту главы Госдепа США"
iex> Expression.evaluate_as_string!(
...> "@right(\"Умерла Мадлен Олбрайт - первая женщина на посту главы Госдепа США\", 20)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"ту главы Госдепа США"
second(ctx, date)
Returns only the second of a datetime (0 to 59)
example-1
Example 1:
When used in the following Stack expression it returns a value of type Integer: 8
when used with the following context:
%{"now" => ~U[2023-05-30 17:13:08.176335Z]}
> second(now)
8
When used as an expression in text, prepend it with an @
:
> "... @second(now) ..."
"8"
..$> import ExUnit.Assertions
..$> result = Expression.evaluate_block!(
...> "second(now)",
...> %{"now" => ~U[2023-05-30 17:13:08.176335Z]},
...> Expression.Callbacks.Standard
...> )
..$> assert 8 = result
8
..$> Expression.evaluate_as_string!(
...> "@second(now)",
...> %{"now" => ~U[2023-05-30 17:13:08.176335Z]},
...> Expression.Callbacks.Standard
...> )
"8"
substitute(ctx, subject, pattern, replacement)
Substitutes new_text for old_text in a text string. If instance_num is given, then only that instance will be substituted
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "I can do"
.
> substitute("I can't", "can't", "can do")
"I can do"
When used as an expression in text, prepend it with an @
:
> "... @substitute("I can't", "can't", "can do") ..."
"I can do"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "substitute(\"I can't\", \"can't\", \"can do\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "I can do" = result
"I can do"
iex> Expression.evaluate_as_string!(
...> "@substitute(\"I can't\", \"can't\", \"can do\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"I can do"
sum_vargs(ctx, arguments)
Returns the sum of all arguments, equivalent to the + operator
You have @SUM(contact.reports, contact.forms) reports and forms
example-1
Example 1:
When used in the following Stack expression it returns a value of type Integer: 6
.
> sum(1, 2, 3)
6
When used as an expression in text, prepend it with an @
:
> "... @sum(1, 2, 3) ..."
"6"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "sum(1, 2, 3)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 6 = result
6
iex> Expression.evaluate_as_string!(
...> "@sum(1, 2, 3)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"6"
time(ctx, hours, minutes, seconds)
Defines a time value which can be used for time arithmetic
example-1
Example 1:
When used in the following Stack expression it returns a value of type Time: ~T[12:13:14]
.
> time(12, 13, 14)
~T[12:13:14]
When used as an expression in text, prepend it with an @
:
> "... @time(12, 13, 14) ..."
"~T[12:13:14]"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "time(12, 13, 14)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert ~T[12:13:14] = result
~T[12:13:14]
iex> Expression.evaluate_as_string!(
...> "@time(12, 13, 14)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"~T[12:13:14]"
timevalue(ctx, expression)
Converts time stored in text to an actual time
example-1
Example 1:
When used in the following Stack expression it returns a value of type Time: ~T[02:30:00]
.
> timevalue("2:30")
~T[02:30:00]
When used as an expression in text, prepend it with an @
:
> "... @timevalue("2:30") ..."
"~T[02:30:00]"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "timevalue(\"2:30\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert ~T[02:30:00] = result
~T[02:30:00]
iex> Expression.evaluate_as_string!(
...> "@timevalue(\"2:30\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"~T[02:30:00]"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Time: ~T[02:30:55]
.
> timevalue("2:30:55")
~T[02:30:55]
When used as an expression in text, prepend it with an @
:
> "... @timevalue("2:30:55") ..."
"~T[02:30:55]"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "timevalue(\"2:30:55\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert ~T[02:30:55] = result
~T[02:30:55]
iex> Expression.evaluate_as_string!(
...> "@timevalue(\"2:30:55\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"~T[02:30:55]"
today(ctx)
Returns the current date
example-1
Example 1:
When used in the following Stack expression it returns a value of type Date: ~D[2023-05-30]
.
> today()
~D[2023-05-30]
When used as an expression in text, prepend it with an @
:
> "... @today() ..."
"2023-05-30"
..$> import ExUnit.Assertions
..$> result = Expression.evaluate_block!(
...> "today()",
...> %{},
...> Expression.Callbacks.Standard
...> )
..$> assert ~D[2023-05-30] = result
~D[2023-05-30]
..$> Expression.evaluate_as_string!(
...> "@today()",
...> %{},
...> Expression.Callbacks.Standard
...> )
"2023-05-30"
unichar(ctx, code)
Returns the unicode character specified by a number
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "A"
.
> unichar(65)
"A"
When used as an expression in text, prepend it with an @
:
> "... @unichar(65) ..."
"A"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "unichar(65)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "A" = result
"A"
iex> Expression.evaluate_as_string!(
...> "@unichar(65)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"A"
example-2
Example 2:
When used in the following Stack expression it returns a value of type String: "é"
.
> unichar(233)
"é"
When used as an expression in text, prepend it with an @
:
> "... @unichar(233) ..."
"é"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "unichar(233)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "é" = result
"é"
iex> Expression.evaluate_as_string!(
...> "@unichar(233)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"é"
unicode(ctx, letter)
Returns a numeric code for the first character in a text string
example-1
Example 1:
When used in the following Stack expression it returns a value of type Integer: 65
.
> unicode("A")
65
When used as an expression in text, prepend it with an @
:
> "... @unicode("A") ..."
"65"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "unicode(\"A\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 65 = result
65
iex> Expression.evaluate_as_string!(
...> "@unicode(\"A\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"65"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Integer: 233
.
> unicode("é")
233
When used as an expression in text, prepend it with an @
:
> "... @unicode("é") ..."
"233"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "unicode(\"é\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 233 = result
233
iex> Expression.evaluate_as_string!(
...> "@unicode(\"é\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"233"
upper(ctx, binary)
Converts a text string to uppercase
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "FOO"
.
> upper("foo")
"FOO"
When used as an expression in text, prepend it with an @
:
> "... @upper("foo") ..."
"FOO"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "upper(\"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "FOO" = result
"FOO"
iex> Expression.evaluate_as_string!(
...> "@upper(\"foo\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"FOO"
weekday(ctx, date)
Returns the day of the week of a date (1 for Sunday to 7 for Saturday)
example-1
Example 1:
When used in the following Stack expression it returns a value of type Integer: 1
when used with the following context:
%{"today" => ~D[2022-11-06]}
> weekday(today)
1
When used as an expression in text, prepend it with an @
:
> "... @weekday(today) ..."
"1"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "weekday(today)",
...> %{"today" => ~D[2022-11-06]},
...> Expression.Callbacks.Standard
...> )
iex> assert 1 = result
1
iex> Expression.evaluate_as_string!(
...> "@weekday(today)",
...> %{"today" => ~D[2022-11-06]},
...> Expression.Callbacks.Standard
...> )
"1"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Integer: 3
when used with the following context:
%{"today" => ~D[2022-11-01]}
> weekday(today)
3
When used as an expression in text, prepend it with an @
:
> "... @weekday(today) ..."
"3"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "weekday(today)",
...> %{"today" => ~D[2022-11-01]},
...> Expression.Callbacks.Standard
...> )
iex> assert 3 = result
3
iex> Expression.evaluate_as_string!(
...> "@weekday(today)",
...> %{"today" => ~D[2022-11-01]},
...> Expression.Callbacks.Standard
...> )
"3"
word(ctx, binary, n)
Extracts the nth word from the given text string. If stop is a negative number,
then it is treated as count backwards from the end of the text. If by_spaces is
specified and is true
then the function splits the text into words only by spaces.
Otherwise the text is split by punctuation characters as well
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "cow"
.
> word("hello cow-boy", 2)
"cow"
When used as an expression in text, prepend it with an @
:
> "... @word("hello cow-boy", 2) ..."
"cow"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "word(\"hello cow-boy\", 2)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "cow" = result
"cow"
iex> Expression.evaluate_as_string!(
...> "@word(\"hello cow-boy\", 2)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"cow"
example-2
Example 2:
When used in the following Stack expression it returns a value of type String: "cow-boy"
.
> word("hello cow-boy", 2, true)
"cow-boy"
When used as an expression in text, prepend it with an @
:
> "... @word("hello cow-boy", 2, true) ..."
"cow-boy"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "word(\"hello cow-boy\", 2, true)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "cow-boy" = result
"cow-boy"
iex> Expression.evaluate_as_string!(
...> "@word(\"hello cow-boy\", 2, true)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"cow-boy"
example-3
Example 3:
When used in the following Stack expression it returns a value of type String: "boy"
.
> word("hello cow-boy", -1)
"boy"
When used as an expression in text, prepend it with an @
:
> "... @word("hello cow-boy", -1) ..."
"boy"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "word(\"hello cow-boy\", -1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "boy" = result
"boy"
iex> Expression.evaluate_as_string!(
...> "@word(\"hello cow-boy\", -1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"boy"
word(ctx, binary, n, by_spaces)
word_count(ctx, binary)
Returns the number of words in the given text string. If by_spaces is specified and is true
then the function splits the text into words only by spaces. Otherwise the text is split by punctuation characters as well
> You entered @word_count("one two three") words
You entered 3 words
example-1
Example 1:
When used in the following Stack expression it returns a value of type Integer: 3
.
> word_count("hello cow-boy")
3
When used as an expression in text, prepend it with an @
:
> "... @word_count("hello cow-boy") ..."
"3"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "word_count(\"hello cow-boy\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 3 = result
3
iex> Expression.evaluate_as_string!(
...> "@word_count(\"hello cow-boy\")",
...> %{},
...> Expression.Callbacks.Standard
...> )
"3"
example-2
Example 2:
When used in the following Stack expression it returns a value of type Integer: 2
.
> word_count("hello cow-boy", true)
2
When used as an expression in text, prepend it with an @
:
> "... @word_count("hello cow-boy", true) ..."
"2"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "word_count(\"hello cow-boy\", true)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert 2 = result
2
iex> Expression.evaluate_as_string!(
...> "@word_count(\"hello cow-boy\", true)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"2"
word_count(ctx, binary, by_spaces)
word_slice(ctx, binary, start)
Extracts a substring of the words beginning at start, and up to but not-including stop.
If stop is omitted then the substring will be all words from start until the end of the text.
If stop is a negative number, then it is treated as count backwards from the end of the text.
If by_spaces is specified and is true
then the function splits the text into words only by spaces.
Otherwise the text is split by punctuation characters as well
example-1
Example 1:
When used in the following Stack expression it returns a value of type String: "expressions are"
.
> word_slice("FLOIP expressions are fun", 2, 4)
"expressions are"
When used as an expression in text, prepend it with an @
:
> "... @word_slice("FLOIP expressions are fun", 2, 4) ..."
"expressions are"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "word_slice(\"FLOIP expressions are fun\", 2, 4)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "expressions are" = result
"expressions are"
iex> Expression.evaluate_as_string!(
...> "@word_slice(\"FLOIP expressions are fun\", 2, 4)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"expressions are"
example-2
Example 2:
When used in the following Stack expression it returns a value of type String: "expressions are fun"
.
> word_slice("FLOIP expressions are fun", 2)
"expressions are fun"
When used as an expression in text, prepend it with an @
:
> "... @word_slice("FLOIP expressions are fun", 2) ..."
"expressions are fun"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "word_slice(\"FLOIP expressions are fun\", 2)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "expressions are fun" = result
"expressions are fun"
iex> Expression.evaluate_as_string!(
...> "@word_slice(\"FLOIP expressions are fun\", 2)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"expressions are fun"
example-3
Example 3:
When used in the following Stack expression it returns a value of type String: "FLOIP expressions"
.
> word_slice("FLOIP expressions are fun", 1, -2)
"FLOIP expressions"
When used as an expression in text, prepend it with an @
:
> "... @word_slice("FLOIP expressions are fun", 1, -2) ..."
"FLOIP expressions"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "word_slice(\"FLOIP expressions are fun\", 1, -2)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "FLOIP expressions" = result
"FLOIP expressions"
iex> Expression.evaluate_as_string!(
...> "@word_slice(\"FLOIP expressions are fun\", 1, -2)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"FLOIP expressions"
example-4
Example 4:
When used in the following Stack expression it returns a value of type String: "fun"
.
> word_slice("FLOIP expressions are fun", -1)
"fun"
When used as an expression in text, prepend it with an @
:
> "... @word_slice("FLOIP expressions are fun", -1) ..."
"fun"
iex> import ExUnit.Assertions
iex> result = Expression.evaluate_block!(
...> "word_slice(\"FLOIP expressions are fun\", -1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
iex> assert "fun" = result
"fun"
iex> Expression.evaluate_as_string!(
...> "@word_slice(\"FLOIP expressions are fun\", -1)",
...> %{},
...> Expression.Callbacks.Standard
...> )
"fun"
word_slice(ctx, binary, start, stop)
word_slice(ctx, binary, start, stop, by_spaces)
year(ctx, date)
Returns only the year of a date
example-1
Example 1:
When used in the following Stack expression it returns a value of type Integer: 2023
when used with the following context:
%{"now" => ~U[2023-05-30 17:13:08.183483Z]}
> year(now)
2023
When used as an expression in text, prepend it with an @
:
> "... @year(now) ..."
"2023"
..$> import ExUnit.Assertions
..$> result = Expression.evaluate_block!(
...> "year(now)",
...> %{"now" => ~U[2023-05-30 17:13:08.183483Z]},
...> Expression.Callbacks.Standard
...> )
..$> assert 2023 = result
2023
..$> Expression.evaluate_as_string!(
...> "@year(now)",
...> %{"now" => ~U[2023-05-30 17:13:08.183483Z]},
...> Expression.Callbacks.Standard
...> )
"2023"