-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure name field is optional on subscribe form
- Loading branch information
1 parent
d0c850e
commit 4265fb9
Showing
3 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule Changelog.MapKit do | ||
alias Changelog.StringKit | ||
@doc """ | ||
Returns a map with all key/value pairs removed where the value was blank | ||
""" | ||
def sans_blanks(map) do | ||
map | ||
|> Enum.reject(fn {_k, v} -> StringKit.blank?(v) end) | ||
|> Enum.reduce(%{}, fn {k, v}, acc -> Map.put(acc, k, v) end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule Changelog.MapKitTest do | ||
use ExUnit.Case | ||
|
||
alias Changelog.MapKit | ||
|
||
describe "sans_blanks/1" do | ||
test "returns a map that removes blank values" do | ||
map = %{"name" => "", "email" => nil, "ohai" => "yes"} | ||
|
||
assert MapKit.sans_blanks(map) == %{"ohai" => "yes"} | ||
end | ||
end | ||
end |