Add RDF.Description.subject/1 and RDF.Description.change_subject/2
This commit is contained in:
parent
e9432ef556
commit
58c5772011
3 changed files with 28 additions and 1 deletions
|
@ -7,6 +7,10 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
|
|||
|
||||
## Unreleased
|
||||
|
||||
### Added
|
||||
|
||||
- `RDF.Description.subject/1` and `RDF.Description.change_subject/2`
|
||||
|
||||
### Changed
|
||||
|
||||
- for consistency reasons the internal `:id` struct field of `RDF.BlankNode` was renamed
|
||||
|
|
|
@ -50,6 +50,18 @@ defmodule RDF.Description do
|
|||
def new({subject, predicate, object}), do: new(subject) |> add({predicate, object})
|
||||
def new(subject), do: %__MODULE__{subject: coerce_subject(subject)}
|
||||
|
||||
@doc """
|
||||
Returns the subject IRI or blank node of a description.
|
||||
"""
|
||||
def subject(%__MODULE__{} = description), do: description.subject
|
||||
|
||||
@doc """
|
||||
Changes the subject of a description.
|
||||
"""
|
||||
def change_subject(%__MODULE__{} = description, new_subject) do
|
||||
%__MODULE__{description | subject: coerce_subject(new_subject)}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Add statements to a `RDF.Description`.
|
||||
|
||||
|
@ -130,7 +142,9 @@ defmodule RDF.Description do
|
|||
|
||||
Note: As it is a destructive function this function is more strict in its handling of
|
||||
`RDF.Description`s than `add/3`. The subject of a `RDF.Description` to be put must
|
||||
match.
|
||||
match. If you want to overwrite existing statements with those from the description of
|
||||
another subject, you'll have to explicitly change the subject with `change_subject/2`
|
||||
first before using `put/3`.
|
||||
|
||||
## Examples
|
||||
|
||||
|
|
|
@ -34,6 +34,15 @@ defmodule RDF.DescriptionTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "subject/1" do
|
||||
assert Description.subject(description()) == description().subject
|
||||
end
|
||||
|
||||
test "change_subject/2" do
|
||||
assert Description.change_subject(description(), EX.NewSubject).subject ==
|
||||
iri(EX.NewSubject)
|
||||
end
|
||||
|
||||
describe "add/3" do
|
||||
test "with a triple" do
|
||||
assert Description.add(description(), {iri(EX.Subject), EX.predicate(), iri(EX.Object)})
|
||||
|
|
Loading…
Reference in a new issue