Delimited.Field (Delimited v0.1.0)

Copy Markdown View Source

One declared column.

Built by Delimited.Schema.field/3 at compile time. Read it back with MySchema.__delimited__(:fields) when you need to generate documentation, a template file, or a user-facing column list.

Options

  • :header - the column name in the file. Defaults to the field name. Set it whenever the file's spelling is not a valid atom, which is most real files: field :employee_id, :integer, header: "Employee ID".

  • :default - the term used when the cell is empty or the column is absent. Defaults to nil. The default is used as declared and is never cast, so it must already be a value of the field's type.

  • :required - when true, an empty cell is a :required_field_missing error instead of nil. Defaults to false. A required field cannot also declare a default, because the default would make the requirement unreachable.

  • :trim - strip surrounding whitespace from the cell before reading it. Defaults to the dialect's :trim.

  • :null - the strings that mean "no value" for this field. Defaults to the dialect's :null. Use it for the file that writes "N/A" in one column and leaves the rest blank.

Any other option is passed to a custom type. Built-in types reject unknown options, so a misspelt :heder fails the build rather than reading the wrong column.

Summary

Types

t()

@type t() :: %Delimited.Field{
  default: term(),
  header: String.t(),
  name: atom(),
  null: [String.t()] | nil,
  opts: keyword(),
  required: boolean(),
  trim: boolean() | nil,
  type: Delimited.Type.t()
}