Add functions terms/1 and iris/1 on RDF.PropertyMap
This commit is contained in:
parent
6e1b6213c4
commit
d3fa2a4f02
3 changed files with 25 additions and 0 deletions
|
@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
|
||||||
- a `RDF.Graph` builder DSL available under the `RDF.Graph.build/2` function
|
- a `RDF.Graph` builder DSL available under the `RDF.Graph.build/2` function
|
||||||
- `RDF.Graph.new/2` and `RDF.Graph.add/2` support the addition of `RDF.Dataset`s
|
- `RDF.Graph.new/2` and `RDF.Graph.add/2` support the addition of `RDF.Dataset`s
|
||||||
- new guards in `RDF.Guards`: `is_statement/1` and `is_quad/1`
|
- new guards in `RDF.Guards`: `is_statement/1` and `is_quad/1`
|
||||||
|
- `RDF.PropertyMap.terms/1` and `RDF.PropertyMap.iris/1`
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,18 @@ defmodule RDF.PropertyMap do
|
||||||
def from_opts(nil), do: nil
|
def from_opts(nil), do: nil
|
||||||
def from_opts(opts), do: if(property_map = Keyword.get(opts, :context), do: new(property_map))
|
def from_opts(opts), do: if(property_map = Keyword.get(opts, :context), do: new(property_map))
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns the list of all terms in the given `property_map`.
|
||||||
|
"""
|
||||||
|
@spec terms(t) :: [atom]
|
||||||
|
def terms(%__MODULE__{iris: iris}), do: Map.keys(iris)
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns the list of all IRIs in the given `property_map`.
|
||||||
|
"""
|
||||||
|
@spec iris(t) :: [IRI.t()]
|
||||||
|
def iris(%__MODULE__{terms: terms}), do: Map.keys(terms)
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Returns the IRI for the given `term` in `property_map`.
|
Returns the IRI for the given `term` in `property_map`.
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,18 @@ defmodule RDF.PropertyMapTest do
|
||||||
) == @example_property_map
|
) == @example_property_map
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "terms/1" do
|
||||||
|
assert PropertyMap.terms(@example_property_map) == [:Baz, :bar, :foo]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "iris/1" do
|
||||||
|
assert PropertyMap.iris(@example_property_map) == [
|
||||||
|
~I<http://example.com/Baz>,
|
||||||
|
~I<http://example.com/test/bar>,
|
||||||
|
~I<http://example.com/test/foo>
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
describe "iri/2" do
|
describe "iri/2" do
|
||||||
test "when the given term exists" do
|
test "when the given term exists" do
|
||||||
assert PropertyMap.iri(@example_property_map, "foo") ==
|
assert PropertyMap.iri(@example_property_map, "foo") ==
|
||||||
|
|
Loading…
Reference in a new issue