diff --git a/lib/rdf/prefix_map.ex b/lib/rdf/prefix_map.ex index de4e05a..68981b6 100644 --- a/lib/rdf/prefix_map.ex +++ b/lib/rdf/prefix_map.ex @@ -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`. diff --git a/test/unit/prefix_map_test.exs b/test/unit/prefix_map_test.exs index d4edaba..595dc80 100644 --- a/test/unit/prefix_map_test.exs +++ b/test/unit/prefix_map_test.exs @@ -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