IDUtils.Schemes.Handle (id_utils v0.1.0)

Copy Markdown View Source

Handle System scheme.

See https://www.rfc-editor.org/info/rfc3651/

Summary

Functions

Builds a URI for the given Handle.

Checks whether a string can be matched as a Handle with a HNR NA.

Checks whether a string can be matched as a Handle.

Normalizes a Handle.

Checks whether a string starts with a Handle prefix.

Functions

build_uri(handle)

Builds a URI for the given Handle.

Examples

iex> IDUtils.Schemes.Handle.build_uri("20.1000/5555")
{:ok, %URI{scheme: "https", host: "hdl.handle.net", path: "/20.1000/5555", port: 443}}

hnr?(string)

@spec hnr?(binary()) :: boolean()

Checks whether a string can be matched as a Handle with a HNR NA.

The Handle.Net Registry (HNR) allots naming authorities of the form "20.500" followed by four or more digits, e.g., 20.500.1234.

Examples

iex> IDUtils.Schemes.Handle.hnr?("20.500.1234/100")
true

iex> IDUtils.Schemes.Handle.hnr?("https://hdl.handle.net/20.500.1234/100")
true

iex> IDUtils.Schemes.Handle.hnr?("10.1000/182")
false

match?(string)

Checks whether a string can be matched as a Handle.

Limited significance

The Handle System's very generic namespace (RFC 3651 basically specifies "UTF8 except /") means that many shapes will "match" as a Handle, such as any scheme://host/... URL, arbitrary strings with whitespace that happen to contain a slash, etc.

For matching more narrowly according to the Handle.Net Registry (HNR) conventions use hnr?/1.

Examples

iex> IDUtils.Schemes.Handle.match?("20.1000/100")
true

iex> IDUtils.Schemes.Handle.match?("https://hdl.handle.net/20.1000/5555")
true

iex> IDUtils.Schemes.Handle.match?("hello world/foo")
true

iex> IDUtils.Schemes.Handle.match?("https://example.com")
true

normalize(string)

Normalizes a Handle.

Examples

iex> IDUtils.Schemes.Handle.normalize("20.1000/5555")
{:ok, "20.1000/5555"}

iex> IDUtils.Schemes.Handle.normalize("https://hdl.handle.net/20.1000/5555")
{:ok, "20.1000/5555"}

iex> IDUtils.Schemes.Handle.normalize("hdl: 2381/12345")
{:ok, "2381/12345"}

iex> IDUtils.Schemes.Handle.normalize("not-a-handle")
{:error, :invalid_identifier}

prefix?(string)

@spec prefix?(binary()) :: boolean()

Checks whether a string starts with a Handle prefix.

Examples

iex> IDUtils.Schemes.Handle.prefix?("https://hdl.handle.net/20.1000/100")
true

iex> IDUtils.Schemes.Handle.prefix?("info:hdl/20.1000/100")
true

iex> IDUtils.Schemes.Handle.prefix?("20.1000/100")
false