GS1.ValidatorConfig (gs1_barcode v0.1.2)
View SourceGS1 Validator config struct.
Defines the rules used to validate a parsed GS1.DataStructure.t/0.
Supports builder style, allowing to chain configuration options.
Options
:fail_fast- Iftrue, validation stops when error found. Defaults totrue.:required_ais- list of AIs that must appear in the Data Structure.:forbidden_ais- ist of AIs that must NOT appear.:constraints- map of custom validation functions keyed by AI.
Summary
Functions
Creates a new GS1.ValidatorConfig with optional default values.
Adds a custom validation constraint for a specific AI.
Adds a single AI to the forbidden list.
Adds a single AI to the required list.
Sets (replaces) map of constraints.
Sets the fail_fast strategy.
Sets (replaces) list of forbidden AIs.
Sets (replaces) list of required AIs.
Types
@type t() :: %GS1.ValidatorConfig{ constraints: %{required(String.t()) => GS1.Validator.Constraint.predicate()}, fail_fast: boolean(), forbidden_ais: [String.t()], required_ais: [String.t()] }
Validation strategy and ruleset.
Functions
@spec new( fail_fast: boolean(), required_ais: [String.t()], forbidden_ais: [String.t()], constraints: %{required(String.t()) => GS1.Validator.Constraint.predicate()} ) :: t()
Creates a new GS1.ValidatorConfig with optional default values.
Examples
iex> GS1.ValidatorConfig.new(fail_fast: false, required_ais: ["01", "21"])
%GS1.ValidatorConfig{
fail_fast: false,
required_ais: ["01", "21"],
forbidden_ais: [],
constraints: %{}
}
@spec put_constraint(t(), String.t(), GS1.Validator.Constraint.predicate()) :: t()
Adds a custom validation constraint for a specific AI.
Examples
iex> GS1.ValidatorConfig.new()
...> |> GS1.ValidatorConfig.put_constraint("01", fn val -> String.length(val) == 14 end)
Adds a single AI to the forbidden list.
Adds a single AI to the required list.
@spec set_constraints(t(), %{ required(String.t()) => GS1.Validator.Constraint.predicate() }) :: t()
Sets (replaces) map of constraints.
Sets the fail_fast strategy.
Sets (replaces) list of forbidden AIs.
Sets (replaces) list of required AIs.