View Source Posexional.Field.Value (posexional v1.1.0-rc.0)

this module represent a single field in a row of a positional file

Summary

Types

@type t() :: %Posexional.Field.Value{
  alignment: term(),
  default: term(),
  filler: term(),
  name: term(),
  size: term()
}

Functions

Link to this function

new(name, size, opts \\ [])

View Source
@spec new(atom(), integer(), Keyword.t()) :: t()
@spec write(t(), binary()) :: binary()

outputs a field

Examples

iex> Posexional.Field.Value.write(Posexional.Field.Value.new(:test, 5), "test")
"test "

iex> Posexional.Field.Value.write(Posexional.Field.Value.new(:test, 5), "too long")
** (RuntimeError) The value too long is too long for the test field. The maximum size is 5 while the value is 8

iex> Posexional.Field.Value.write(Posexional.Field.Value.new(:test, 10), "test")
"test      "

iex> Posexional.Field.Value.write(Posexional.Field.Value.new(:test, 10), "test")
"test      "

iex> Posexional.Field.Value.write(Posexional.Field.Value.new(:test, 10, filler: ?0), "test")
"test000000"

iex> Posexional.Field.Value.write(Posexional.Field.Value.new(:test, 10, filler: ?0, alignment: :right), "test")
"000000test"

iex> Posexional.Field.Value.write(Posexional.Field.Value.new(:test, 10), 50)
** (RuntimeError) The value provided for the test field doesn't seem to be a string