The CitableTrait

The CitableBase package defines a CitableTrait. For any Julia type, the value of the trait is identified by a singleton value returned by the citabletrait function. By default, the value of the trait is NotCitable(). (See a fuller discussion in the documentation for CitableBase).

The CitableText package defines a singleton-type CitableByCtsUrn which you use as the value for CitableTrait for your own types of content identified by CtsUrns. Here is a brief example.

First define your type with a CtsUrn.

using CitableBase, CitableText

struct TinyText <: Citable
    urn::CtsUrn
    txt::AbstractString
end
ctsurn = CtsUrn("urn:cts:greekLit:tlg0012.tlg001.msA:")
txt = "The Iliad"
tiny = TinyText(ctsurn, txt)
Main.TinyText(urn:cts:greekLit:tlg0012.tlg001.msA:, "The Iliad")

Override the citabletrait function when its parameter is the type TinyText, and return the concrete value CitableByCtsUrn().

import CitableBase: citabletrait
function citabletrait(::Type{TinyText})
    CitableByCtsUrn()
end
citabletrait (generic function with 2 methods)

Check the result:

citabletrait(typeof(tiny))
CitableByCtsUrn()

Now you can use the citable function (from CitableBase) to check whether individual objects of your new type are citable.

citable(tiny)
true

At this point, you can also implement the required functions of the CitableTrait, urn and label.

import CitableBase: urn
function urn(tinyText::TinyText)
    tinyText.urn
end
function label(tinyText::TinyText)
    string(tinyText.urn) * ": " * tinyText.txt
end
label (generic function with 1 method)
urn(tiny)
urn:cts:greekLit:tlg0012.tlg001.msA:
label(tiny)
"urn:cts:greekLit:tlg0012.tlg001.msA:: The Iliad"