Add RDF.PrefixMap.drop/2

This commit is contained in:
Marcel Otto 2019-03-30 20:29:48 +01:00
parent ec33614880
commit 6c9f580cab
2 changed files with 34 additions and 0 deletions

View file

@ -212,6 +212,26 @@ defmodule RDF.PrefixMap do
delete(prefix_map, String.to_atom(prefix))
end
@doc """
Drops the given `prefixes` from the given `prefix_map`.
If `prefixes` contains prefixes that are not in `prefix_map`, they're simply ignored.
"""
def drop(prefix_map, prefixes)
def drop(%__MODULE__{map: map}, prefixes) do
%__MODULE__{
map:
Map.drop(
map,
Enum.map(prefixes, fn
prefix when is_binary(prefix) -> String.to_atom(prefix)
other -> other
end)
)
}
end
@doc """
Returns the namespace for the given prefix in the given `RDF.PrefixMap`.

View file

@ -208,6 +208,20 @@ defmodule RDF.PrefixMapTest do
end
end
describe "drop/2" do
test "when a mapping of the given prefix exists" do
assert PrefixMap.drop(@example3, [:ex3, :ex2, :ex]) == @example1
end
test "when no mapping of the given prefix exists" do
assert PrefixMap.drop(@example1, [:ex2]) == @example1
end
test "with the prefixes are given as strings" do
assert PrefixMap.drop(@example3, ["ex3", :ex2]) == @example1
end
end
describe "namespace/2" do
test "when a mapping of the given prefix exists" do
assert PrefixMap.namespace(@example2, :ex2) == @ex_ns2