Skip to main content

Conversion Functions

This section describes the following conversion functions.

to_n

to_n(<string>)

to_n converts a string into a number. to_n may appear when defining datasource fields or in validations.

Example:

to_n("10") # 10 

to_s

to_s(<string>)

to_s converts a number into a string. to_s may appear when defining datasource fields or in validations.

Example:

to_s(10) # "10" 

to_b

to_b(<anything>)

to_b converts anything into a boolean value of true or false. For numbers, it will evaluate to true if the number is not zero. For strings, it will evaluate to true if the string is non-empty. For arrays, it will evaluate to true if the array length is greater than 0. to_b may appear when defining datasource fields or in validations.

Examples:

to_b(0) # false 
to_b(10) # true
to_b("") # false
to_b("any value") # true

to_d

to_d(<string>)

to_d converts a string into a date in the UTC timezone so it can be used in comparisons. It will make a best effort to convert most common date formats.

Examples:

to_d("2009-11-10 04:10:06 -0700") # Ruby default format 
to_d("2009-11-10T11:10:06Z") # RFC3339
gt(to_d(some_timestamp), now) # true if some_timestamp takes place in the future