Packages

Generic Elixir models and portable validation for RelayMark documents and manifests

Current section

Files

Jump to
relay_mark_elixir lib relay_mark annotation.ex
Raw

lib/relay_mark/annotation.ex

defmodule RelayMark.Annotation do
@moduledoc "RelayMark annotation struct."
alias RelayMark.Inline
defstruct id: nil,
type: nil,
anchor: %{},
props: %{},
content: []
@type t :: %__MODULE__{
id: String.t(),
type: String.t(),
anchor: map(),
props: map(),
content: [Inline.t()]
}
@spec from_map(map()) :: t()
def from_map(map) do
%__MODULE__{
id: Map.fetch!(map, "id"),
type: Map.fetch!(map, "type"),
anchor: Map.fetch!(map, "anchor"),
props: Map.get(map, "props", %{}),
content: Enum.map(Map.get(map, "content", []), &Inline.from_map/1)
}
end
end