lofi v0.1.5 Lofi.Tags

Utilities for working with Lofi element tags

Summary

Functions

Fetches the value for a specific name in the given tags

Get value for a content tag

Check whether a tags map has a certain flag tag

Functions

fetch_content(tags, name)

Fetches the value for a specific name in the given tags

iex> Lofi.Tags.fetch_content(%{"name" => {:content, %{texts: ["Alice Jones"]}}, "abc" => {:flag, true}}, "name")
{:ok, %{texts: ["Alice Jones"]}}

iex> Lofi.Tags.fetch_content(%{"name" => {:content, %{texts: ["Alice Jones"]}}, "abc" => {:flag, true}}, "abc")
{:error, :not_content}

iex> Lofi.Tags.fetch_content(%{"name" => {:content, %{texts: ["Alice Jones"]}}, "abc" => {:flag, true}}, "def")
{:error, :missing}
get_content(tags, name, default \\ nil)

Get value for a content tag

iex> Lofi.Tags.get_content(%{"name" => {:content, %{texts: ["Alice Jones"]}}, "abc" => {:flag, true}}, "name")
%{texts: ["Alice Jones"]}

iex> Lofi.Tags.get_content(%{"name" => {:content, %{texts: ["Alice Jones"]}}, "abc" => {:flag, true}}, "abc")
nil

iex> Lofi.Tags.get_content(%{"name" => {:content, %{texts: ["Alice Jones"]}}, "abc" => {:flag, true}}, "abc", "default")
"default"
has_flag(tags, name)

Check whether a tags map has a certain flag tag

iex> Lofi.Tags.has_flag(%{"abc" => {:flag, true}}, "abc")
true

iex> Lofi.Tags.has_flag(%{"abc" => {:flag, true}}, "def")
false

iex> Lofi.Tags.has_flag(%{"abc" => {:content, %{texts: ["text"]}}}, "abc")
false