AshReports.Variable (ash_reports v0.1.0)

Represents a variable that accumulates values during report execution.

Variables can perform calculations like sum, count, average, etc., and can be reset at different scopes (detail, group, page, or report level).

Summary

Functions

Calculates the next value for the variable based on its type.

Returns the default initial value for a variable type.

Gets the display value for the variable (handles average calculation).

Creates a new Variable struct with the given name and options.

Checks if this variable should reset when the given scope changes.

Types

reset_scope()

@type reset_scope() :: :detail | :group | :page | :report

t()

@type t() :: %AshReports.Variable{
  expression: Ash.Expr.t(),
  initial_value: any(),
  name: atom(),
  reset_group: pos_integer() | nil,
  reset_on: reset_scope(),
  type: variable_type()
}

variable_type()

@type variable_type() :: :sum | :count | :average | :min | :max | :custom

Functions

calculate_next_value(variable, current, new_value)

@spec calculate_next_value(t(), any(), any()) :: any()

Calculates the next value for the variable based on its type.

default_initial_value(atom)

@spec default_initial_value(variable_type()) :: any()

Returns the default initial value for a variable type.

get_display_value(variable, value)

@spec get_display_value(t(), any()) :: any()

Gets the display value for the variable (handles average calculation).

new(name, opts \\ [])

@spec new(atom(), Keyword.t()) :: t()

Creates a new Variable struct with the given name and options.

should_reset?(variable, scope, group_level)

@spec should_reset?(t(), reset_scope(), pos_integer() | nil) :: boolean()

Checks if this variable should reset when the given scope changes.