use the IRI sigil

This commit is contained in:
Marcel Otto 2017-04-10 03:06:20 +02:00
parent b167cd7e8e
commit d56e9b03fc
7 changed files with 15 additions and 7 deletions

View file

@ -4,6 +4,8 @@ defmodule RDF do
@doc """
Generator function for URIs from strings or term atoms of a `RDF.Namespace`.
This function is used for the `~I` sigil.
## Examples
iex> RDF.uri("http://www.example.com/foo")

View file

@ -23,7 +23,7 @@ defmodule RDF.Quad do
# Examples
iex> RDF.Quad.new("http://example.com/S", "http://example.com/p", 42, "http://example.com/Graph")
{RDF.uri("http://example.com/S"), RDF.uri("http://example.com/p"), RDF.literal(42), RDF.uri("http://example.com/Graph")}
{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42), ~I<http://example.com/Graph>}
"""
def new(subject, predicate, object, graph_context) do
{
@ -44,7 +44,7 @@ defmodule RDF.Quad do
# Examples
iex> RDF.Quad.new {"http://example.com/S", "http://example.com/p", 42, "http://example.com/Graph"}
{RDF.uri("http://example.com/S"), RDF.uri("http://example.com/p"), RDF.literal(42), RDF.uri("http://example.com/Graph")}
{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42), ~I<http://example.com/Graph>}
"""
def new({subject, predicate, object, graph_context}),
do: new(subject, predicate, object, graph_context)

View file

@ -3,6 +3,8 @@ defmodule RDF.Sigils do
@doc ~S"""
Handles the sigil `~I` for IRIs.
Note: The given IRI string is precompiled into an IRI struct.
## Examples
iex> import RDF.Sigils

View file

@ -26,7 +26,7 @@ defmodule RDF.Triple do
# Examples
iex> RDF.Triple.new("http://example.com/S", "http://example.com/p", 42)
{RDF.uri("http://example.com/S"), RDF.uri("http://example.com/p"), RDF.literal(42)}
{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42)}
"""
def new(subject, predicate, object) do
{
@ -46,7 +46,7 @@ defmodule RDF.Triple do
# Examples
iex> RDF.Triple.new {"http://example.com/S", "http://example.com/p", 42}
{RDF.uri("http://example.com/S"), RDF.uri("http://example.com/p"), RDF.literal(42)}
{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42)}
"""
def new({subject, predicate, object}), do: new(subject, predicate, object)

View file

@ -1,6 +1,8 @@
defmodule RDF.LiteralTest do
use ExUnit.Case
import RDF.Sigils
alias RDF.{Literal}
alias RDF.NS.XSD
@ -35,7 +37,7 @@ defmodule RDF.LiteralTest do
describe "construction with an explicit unknown datatype" do
literal = Literal.new("custom typed value", datatype: "http://example/dt")
assert literal.value == "custom typed value"
assert literal.datatype == RDF.uri("http://example/dt")
assert literal.datatype == ~I<http://example/dt>
end
describe "construction with an explicit known (XSD) datatype" do

View file

@ -1,5 +1,7 @@
defmodule RDF.QuadTest do
use ExUnit.Case
import RDF.Sigils
doctest RDF.Quad
end

View file

@ -1,8 +1,8 @@
defmodule RDF.TripleTest do
use ExUnit.Case
import RDF.Sigils
doctest RDF.Triple
# alias RDF.{Triple, Literal, BlankNode}
end