Kalevala.Brain.Variable (kalevala v0.1.0) View Source

Handle variable data in brain nodes

Replaces variables in the format of ${variable_name}. Works with a dot notation for nested variables.

Example:

The starting data

 %{
   channel_name: "rooms:${room_id}",
   delay: 500,
   text: "Welcome, ${character.name}!"
 }

With the event data

%{
  room_id: "room-id",
  character: %{
    name: "Elias"
  }
}

Will replace to the following

 %{
   channel_name: "rooms:room-id",
   delay: 500,
   text: "Welcome, Elias!"
 }

Link to this section Summary

Functions

Dereference a variable path from a map of data

Detect variables inside of the data

Replace action data variables with event data

Replace detected and dereferenced variables in the data

Walk the resulting data map to convert keys from atoms to strings

Scan the value for a variable, returning Variable structs

Link to this section Functions

Link to this function

dereference(data, variable_path)

View Source

Dereference a variable path from a map of data

Link to this function

dereference_variables(variables, event_data)

View Source
Link to this function

detect_variables(data, path \\ [])

View Source

Detect variables inside of the data

Link to this function

replace(data, event_data)

View Source

Replace action data variables with event data

Link to this function

replace_variables(variables, data)

View Source

Replace detected and dereferenced variables in the data

Fails if any variables still contain an :error value, they were not able to be dereferenced.

Walk the resulting data map to convert keys from atoms to strings

This is useful when sending the resulting data struct to action params

Scan the value for a variable, returning Variable structs