From 5170d226332df72a764981034303921aaa9b29e1 Mon Sep 17 00:00:00 2001 From: Mario Uher Date: Tue, 9 Apr 2024 11:34:10 +0200 Subject: [PATCH] Allow empty attributes --- README.md | 6 +++--- lib/twiml.ex | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index dae49c0..4c3933a 100644 --- a/README.md +++ b/README.md @@ -271,15 +271,15 @@ iex> TwiML.say("Sorry, calls are currently unavailable") """ ``` -Empty attributes are not included in the generated TwiML: +Attributes with a value of nil are excluded from the generated TwiML: ```elixir -iex> TwiML.say("Hello", voice: "", loop: nil) +iex> TwiML.gather(input: "dtmf", finish_on_key: "", num_digits: nil) ...> |> TwiML.to_xml() """ - Hello + \ """ ``` diff --git a/lib/twiml.ex b/lib/twiml.ex index 4c46fa7..cf50bb3 100644 --- a/lib/twiml.ex +++ b/lib/twiml.ex @@ -79,15 +79,14 @@ defmodule TwiML do end defp build_verb(verb, attrs, children) do - verb = verb |> Atom.to_string() |> String.capitalize() + verb = + verb + |> Atom.to_string() + |> String.capitalize() attrs = attrs - |> Enum.reject(fn - {_, nil} -> true - {_, ""} -> true - _ -> false - end) + |> Enum.reject(&is_nil(elem(&1, 1))) |> Enum.map(fn {k, v} -> {camelize(k, :lower), v} end) {verb, attrs, children}