Posexional.Field (posexional v1.2.0)

View Source

generic utility functions for fields

Summary

Functions

true if the value passed contains only the filler value

nil if the value is an empty string, or a string containing only the filler

justify a value given alignment, size and filler char, if the given value is longer it gets trimmed

Functions

contains_only?(v, filler)

true if the value passed contains only the filler value

depositionalize(content, field)

@spec depositionalize(binary(), map()) :: binary()

nil_if_empty(v, filler)

nil if the value is an empty string, or a string containing only the filler

positionalize(value, map)

@spec positionalize(binary(), map()) :: binary()

justify a value given alignment, size and filler char, if the given value is longer it gets trimmed

Examples

iex> Posexional.Field.positionalize("test",
...>   %{alignment: :left, size: 10, filler: ?\s})
"test      "

iex> Posexional.Field.positionalize("test",
...>   %{alignment: :right, size: 10, filler: ?\s})
"      test"

iex> Posexional.Field.positionalize("test",
...>   %{alignment: :right, size: 5, filler: ?\s})
" test"

iex> Posexional.Field.positionalize("test",
...>   %{alignment: :right, size: 5, filler: ?-})
"-test"

iex> Posexional.Field.positionalize("testtest",
...>   %{alignment: :right, size: 5, filler: ?-})
"testt"