NLdoc.Conversion.Reader.Docx.State (NLdoc.Conversion.Reader.Docx v1.1.2)

View Source

This module defines a struct that captures the state of the converter during a Docx conversion.

Summary

Functions

Gets the given field from the state object.

Modifies a state object by setting the given field to the value that field had in the old state.

Sets the given field on the state object to the given value.

Upserts the existence of an asset based on it's relative path.

Types

t()

@type t() :: %NLdoc.Conversion.Reader.Docx.State{
  assets: %{required(String.t()) => String.t()} | nil,
  has_title: boolean() | nil,
  hyperlink_target: (String.t() | nil) | nil,
  numbering_id: (String.t() | nil) | nil,
  styling: NLdoc.Conversion.Reader.Docx.AST.RunProperties.t() | nil
}

Functions

get(state, atom)

@spec get(t(), :has_title) :: boolean()
@spec get(t(), :hyperlink_target) :: String.t() | nil
@spec get(t(), :styling) :: NLdoc.Conversion.Reader.Docx.AST.RunProperties.t()
@spec get(t(), :assets) :: %{required(String.t()) => String.t()}
@spec get(t(), :numbering_id) :: String.t() | nil

Gets the given field from the state object.

This function only accepts fields of the state, which are :has_title, :hyperlink_target, :styling, :assets, :numbering_id. It will raise if the field is not valid.

keep(new_state, old_state, atom)

@spec keep(t(), t(), :has_title) :: t()
@spec keep(t(), t(), :hyperlink_target) :: t()
@spec keep(t(), t(), :styling) :: t()
@spec keep(t(), t(), :assets) :: t()
@spec keep(t(), t(), :numbering_id) :: t()

Modifies a state object by setting the given field to the value that field had in the old state.

This function only accepts fields of the state, which are :has_title, :hyperlink_target, :styling, :assets, :numbering_id. It will raise if the field is not valid.

set(state, atom, value)

@spec set(t(), :has_title, boolean()) :: t()
@spec set(t(), :hyperlink_target, String.t() | nil) :: t()
@spec set(t(), :styling, NLdoc.Conversion.Reader.Docx.AST.RunProperties.t()) :: t()
@spec set(t(), :assets, %{required(String.t()) => String.t()}) :: t()
@spec set(t(), :numbering_id, String.t() | nil) :: t()

Sets the given field on the state object to the given value.

This function only accepts fields of the state, which are :has_title, :hyperlink_target, :styling, :assets, :numbering_id. It will raise if the field is not valid.

upsert_asset(state, relative_path)

@spec upsert_asset(state :: t(), relative_path :: String.t()) :: {String.t(), t()}

Upserts the existence of an asset based on it's relative path.

Examples

iex> alias NLdoc.Conversion.Reader.Docx.State
iex> {uuid, state} = State.upsert_asset(%State{}, "media/image.png")
iex> %{"media/image.png" => ^uuid} = state.assets

iex> alias NLdoc.Conversion.Reader.Docx.State
iex> {"xyz", state} = State.upsert_asset(%State{assets: %{"media/image.png" => "xyz"}}, "media/image.png")
iex> %{"media/image.png" => "xyz"} = state.assets