Add RDF.PrefixMap.drop/2
This commit is contained in:
parent
ec33614880
commit
6c9f580cab
2 changed files with 34 additions and 0 deletions
|
@ -212,6 +212,26 @@ defmodule RDF.PrefixMap do
|
||||||
delete(prefix_map, String.to_atom(prefix))
|
delete(prefix_map, String.to_atom(prefix))
|
||||||
end
|
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 """
|
@doc """
|
||||||
Returns the namespace for the given prefix in the given `RDF.PrefixMap`.
|
Returns the namespace for the given prefix in the given `RDF.PrefixMap`.
|
||||||
|
|
||||||
|
|
|
@ -208,6 +208,20 @@ defmodule RDF.PrefixMapTest do
|
||||||
end
|
end
|
||||||
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
|
describe "namespace/2" do
|
||||||
test "when a mapping of the given prefix exists" do
|
test "when a mapping of the given prefix exists" do
|
||||||
assert PrefixMap.namespace(@example2, :ex2) == @ex_ns2
|
assert PrefixMap.namespace(@example2, :ex2) == @ex_ns2
|
||||||
|
|
Loading…
Reference in a new issue