Cucumberex.ParameterType (cucumberex v0.2.1)

Copy Markdown View Source

A named parameter type with a regexp and transformer.

Summary

Functions

Build a ParameterType struct.

Apply the parameter type's transformer to a list of captures.

Types

t()

@type t() :: %Cucumberex.ParameterType{
  description: String.t() | nil,
  name: String.t(),
  prefer_for_regexp_match: boolean(),
  regexp: Regex.t() | [Regex.t()],
  transformer: (list() -> any()),
  use_for_snippets: boolean()
}

Functions

new(name, regexp, transformer, opts \\ [])

Build a ParameterType struct.

Examples

iex> pt = Cucumberex.ParameterType.new("int", ~r/\d+/, fn [s] -> String.to_integer(s) end)
iex> pt.name
"int"
iex> pt.use_for_snippets
true

iex> pt = Cucumberex.ParameterType.new("x", ~r/x/, fn _ -> nil end, use_for_snippets: false)
iex> pt.use_for_snippets
false

transform(parameter_type, captures)

Apply the parameter type's transformer to a list of captures.

Examples

iex> pt = Cucumberex.ParameterType.new("int", ~r/\d+/, fn [s] -> String.to_integer(s) end)
iex> Cucumberex.ParameterType.transform(pt, ["42"])
42