Ussd.Decision protocol (Ussd v0.2.0)

Copy Markdown View Source

Something that can look at the caller's raw input and say yes or no.

Implemented by every struct in Ussd.Decisions.*, and by anything you build yourself - a decision is just a struct plus a decide/2 clause, so a custom one is as small as:

defmodule MyApp.Decisions.EvenLength do
  defstruct []

  defimpl Ussd.Decision do
    def decide(_decision, actual), do: rem(String.length(actual), 2) == 0
  end
end

Used from transition/2, back/2, paginate/2 and truncate/2 inside use Ussd.State.

Summary

Types

t()

All the types that implement this protocol.

Functions

Whether actual (the caller's raw input) satisfies this decision.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

decide(decision, actual)

@spec decide(t(), String.t()) :: boolean()

Whether actual (the caller's raw input) satisfies this decision.