From d3fa2a4f0296de811172b47193f5c413c425d67a Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Mon, 4 Apr 2022 22:30:08 +0200 Subject: [PATCH] Add functions terms/1 and iris/1 on RDF.PropertyMap --- CHANGELOG.md | 1 + lib/rdf/property_map.ex | 12 ++++++++++++ test/unit/property_map_test.exs | 12 ++++++++++++ 3 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cc49ca..a7998ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 - `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` +- `RDF.PropertyMap.terms/1` and `RDF.PropertyMap.iris/1` ### Changed diff --git a/lib/rdf/property_map.ex b/lib/rdf/property_map.ex index a0cb790..16ac604 100644 --- a/lib/rdf/property_map.ex +++ b/lib/rdf/property_map.ex @@ -57,6 +57,18 @@ defmodule RDF.PropertyMap do def from_opts(nil), do: nil 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 """ Returns the IRI for the given `term` in `property_map`. diff --git a/test/unit/property_map_test.exs b/test/unit/property_map_test.exs index 386424b..8863cc5 100644 --- a/test/unit/property_map_test.exs +++ b/test/unit/property_map_test.exs @@ -35,6 +35,18 @@ defmodule RDF.PropertyMapTest do ) == @example_property_map 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, + ~I, + ~I + ] + end + describe "iri/2" do test "when the given term exists" do assert PropertyMap.iri(@example_property_map, "foo") ==