ymlr v0.0.1 Ymlr.Encoder

Encodes data into YAML strings.

Link to this section Summary

Functions

Encodes the given data as YAML string.

Encodes the given data as YAML string. Raises if it cannot be encoded.

Link to this section Types

Specs

data() :: map() | [data()] | atom() | binary() | number()

Link to this section Functions

Specs

to_s(data()) :: {:ok, binary()} | {:error, binary()}

Encodes the given data as YAML string.

Examples

iex> Ymlr.Encoder.to_s(%{a: 1, b: 2})
{:ok, "a: 1\nb: 2"}

iex> Ymlr.Encoder.to_s({"a", "b"})
{:error, "The given data {\"a\", \"b\"} cannot be converted to YAML."}

Specs

to_s!(data()) :: binary()

Encodes the given data as YAML string. Raises if it cannot be encoded.

Examples

iex> Ymlr.Encoder.to_s!(%{})
"{}"

iex> Ymlr.Encoder.to_s!(%{a: 1, b: 2})
"a: 1\nb: 2"

iex> Ymlr.Encoder.to_s!(%{"a" => "a", "b" => :b, "c" => "true", "d" => "100"})
"a: a\nb: b\nc: 'true'\nd: '100'"

iex> Ymlr.Encoder.to_s!({"a", "b"})
** (ArgumentError) The given data {"a", "b"} cannot be converted to YAML.