Predicator.Evaluator (Predicator v0.9.2) View Source
Evaluator Module
Link to this section Summary
Functions
Execute will evaluate a predicator instruction set.
Link to this section Types
Specs
error_t() :: {:error, InstructionError.t() | ValueError.t() | Predicator.InstructionNotCompleteError.t()}
Error types returned from Predicator.Evaluator
Link to this section Functions
execute(inst, context \\ %{}, opts \\ [map_type: :string, nil_values: ["", nil]])
View SourceExecute will evaluate a predicator instruction set.
If your context struct is using string_keyed map then you will need to pass in the
[map_type: :string]
options to the execute function to evaluate.
Examples:
iex> Predicator.Evaluator.execute([["lit", true]]) true
iex> Predicator.Evaluator.execute([["lit", 2], ["lit", 3], ["compare", "LT"]]) true
iex> Predicator.Evaluator.execute([["load", "age"], ["lit", 18], ["compare", "GT"]], %{age: 19}) true
iex> Predicator.Evaluator.execute([["load", "name"], ["lit", "jrichocean"], ["compare", "EQ"]], %{age: 19}) {:error, %Predicator.ValueError{error: "Non valid load value to evaluate", instruction_pointer: 0, instructions: [["load", "name"], ["lit", "jrichocean"], ["compare", "EQ"]], stack: [], opts: [map_type: :string, nil_values: ["", nil]]}}
iex> Predicator.Evaluator.execute([["load", "age"], ["lit", 18], ["compare", "GT"]], %{"age" => 19}, [map_type: :string]) true