# `TextFSM.Template`
[🔗](https://github.com/amitbashan/textfsm/blob/main/lib/textfsm/template.ex#L1)

Represents the structure of a TextFSM template.

A template consists of:
- Value definitions: The columns to be extracted.
- States: Named collections of rules defining how to process text and transition between states.
- EOF behavior: How to handle the end of the input (record or not).

# `eof_state`

```elixir
@type eof_state() :: :record | :no_record
```

# `state_name`

```elixir
@type state_name() :: String.t()
```

# `t`

```elixir
@type t() :: %TextFSM.Template{
  eof_state: eof_state(),
  states: [TextFSM.Template.State.t()],
  value_definitions: [TextFSM.Template.ValueDefinition.t()]
}
```

# `value_name`

```elixir
@type value_name() :: String.t()
```

# `get_rule`

```elixir
@spec get_rule(t(), state_name(), non_neg_integer()) ::
  nil | TextFSM.Template.State.Rule.t()
```

Retrieves a specific rule from a state by index.

This is mostly used internally by the Engine to fetch the next rule to evaluate.

## Parameters

* `template` - The `TextFSM.Template` struct.
* `state` - The name of the state (String).
* `idx` - The 0-based index of the rule within that state.

## Returns

* `TextFSM.Template.State.Rule.t()` - The rule at the specified index.
* `nil` - If the state or rule index does not exist.

# `template`

```elixir
@spec template(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: non_neg_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()
```

Parses the given `binary` as template.

Returns `{:ok, [token], rest, context, position, byte_offset}` or
`{:error, reason, rest, context, line, byte_offset}` where `position`
describes the location of the template (start position) as `{line, offset_to_start_of_line}`.

To column where the error occurred can be inferred from `byte_offset - offset_to_start_of_line`.

## Options

  * `:byte_offset` - the byte offset for the whole binary, defaults to 0
  * `:line` - the line and the byte offset into that line, defaults to `{1, byte_offset}`
  * `:context` - the initial context value. It will be converted to a map

# `value_names`

```elixir
@spec value_names(t()) :: [value_name()]
```

Returns the names of all values defined in the template.

## Parameters

* `template` - The `TextFSM.Template` struct.

## Returns

* `[String.t()]` - A list of value name strings.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
