Data Attributes

The attribute operator (.) can be used to recursively resolve values from a compound native Python data type such as an object or dictionary. This can be used when the thing which the rule is evaluating has members with their own submembers. If the resolver function fails, the attribute will be checked to determine if it is a builtin attribute.

Builtin Attributes

The following attributes are builtin to the default Context object.

Attribute Name

Attribute Type

ARRAY Attributes

ends_with(prefix)

FUNCTION

is_empty

BOOLEAN

length

FLOAT

starts_with(prefix)

FUNCTION

to_ary

ARRAY

to_set

SET

BYTES Attributes

ends_with(prefix)

FUNCTION

is_empty

BOOLEAN

length

FLOAT

starts_with(prefix)

FUNCTION

to_ary

ARRAY

to_set

SET

decode(encoding)

FUNCTION

DATETIME Attributes

date

DATETIME

day

FLOAT

hour

FLOAT

microsecond

FLOAT

millisecond

FLOAT

minute

FLOAT

month

FLOAT

second

FLOAT

to_epoch

FLOAT

weekday

STRING

year

FLOAT

zone_name

STRING

FLOAT Attributes 1

ceiling

FLOAT

floor

FLOAT

is_nan

BOOLEAN

to_flt

FLOAT

to_str

STRING

MAPPING Attributes

is_empty

BOOLEAN

keys

ARRAY

length

FLOAT

values

ARRAY

SET Attributes

is_empty

BOOLEAN

length

FLOAT

to_ary

ARRAY

to_set

SET

STRING Attributes

as_lower

STRING

as_upper

STRING

encode(encoding)

FUNCTION

ends_with(prefix)

FUNCTION

to_ary

ARRAY

to_flt

FLOAT

to_set

SET

to_str

STRING

to_int

FLOAT

is_empty

BOOLEAN

length

FLOAT

starts_with(prefix)

FUNCTION

TIMEDELTA Attributes

days

FLOAT

seconds

FLOAT

microseconds

FLOAT

total_seconds

FLOAT

FLOAT Attributes 1

Due to the syntax of floating point literals, the attributes must be accessed using parenthesis. For example 3.14.to_str is invalid while (3.14).to_str is valid.

Encoding and Decoding

BYTES values can be converted to STRING values by calling their .decode method. STRING values can be converted to BYTES values by calling their .encode method. This resembles Python’s native functionality and the encoding argument to each is the same, i.e. it can be any encoding name that Python can handle such as UTF-8. In addition to the encoding names that Python can handle, the special names hex, base16 and base64 can be used for transcoding ascii-hex, and base-64 formatted data.

Object Methods

Much like in Python, a method is a function that is associated with an object. They are defined as FUNCTION values and are accessed as attributes.

BYTES decode(STRING encoding) -> STRING

returns:

STRING

encoding:

(STRING) The encoding name to use.

Returns the decoded value.

Added in version 4.5.0.

STRING encode(STRING encoding) -> BYTES

returns:

BYTES

encoding:

(STRING) The encoding name to use.

Returns the encoded value.

Added in version 4.5.0.

ARRAY | BYTES | STRING ends_with(ARRAY | BYTES | STRING suffix) -> BOOLEAN

returns:

BOOLEAN

suffix:

The suffix to check for. The data type must match the object type.

Check whether the value ends with the specified value.

Added in version 4.5.0.

ARRAY | BYTES | STRING starts_with(ARRAY | BYTES | STRING prefix) -> BOOLEAN

returns:

BOOLEAN

prefix:

The prefix to check for. The data type must match the object type.

Check whether the value starts with the specified value.

Added in version 4.5.0.