LiteParse.Config (liteparse v0.1.0)

Copy Markdown View Source

Configuration schema for LiteParse.parse/2 and LiteParse.parse_input/2.

Mirrors the options exposed by the underlying liteparse Rust crate. Pass options as a keyword list, e.g.:

LiteParse.parse("doc.pdf", max_pages: 100, ocr_enabled: false)

Or build a reusable struct:

config = LiteParse.Config.new(max_pages: 100, ocr_language: "spa")
LiteParse.parse("a.pdf", config)
LiteParse.parse_input(bin, config)

Summary

Functions

Builds a %LiteParse.Config{} from a keyword list, applying defaults and validating types.

Converts the validated options into the map shape expected by the NIF: string-keyed map with output_format serialised to a lowercase string.

Returns the validated keyword list (with defaults applied) for the given options. Accepts a keyword list or a %LiteParse.Config{} struct.

Types

t()

@type t() :: %LiteParse.Config{
  dpi: float(),
  max_pages: non_neg_integer(),
  num_workers: non_neg_integer(),
  ocr_enabled: boolean(),
  ocr_language: String.t(),
  ocr_server_url: String.t() | nil,
  output_format: :json | :text,
  password: String.t() | nil,
  preserve_very_small_text: boolean(),
  quiet: boolean(),
  target_pages: String.t() | nil,
  tessdata_path: String.t() | nil
}

Functions

new(opts \\ [])

@spec new(keyword()) :: t()

Builds a %LiteParse.Config{} from a keyword list, applying defaults and validating types.

Raises NimbleOptions.ValidationError on bad input.

Examples

iex> LiteParse.Config.new(max_pages: 50)
%LiteParse.Config{max_pages: 50, ocr_language: "eng", ...}

to_nif(opts)

@spec to_nif(keyword() | t()) :: map()

Converts the validated options into the map shape expected by the NIF: string-keyed map with output_format serialised to a lowercase string.

Accepts a keyword list or a %LiteParse.Config{} struct. When given a struct, it is trusted as already-validated and just converted; when given a keyword list, it goes through NimbleOptions.validate!/2 first.

Internal-facing but public to keep LiteParse.parse/2 decoupled from the schema definition.

validate(opts)

@spec validate(keyword() | t()) :: keyword()

Returns the validated keyword list (with defaults applied) for the given options. Accepts a keyword list or a %LiteParse.Config{} struct.