rdf-ex/lib/rdf/datatypes/boolean.ex
Marcel Otto 2b9aa62d69 core: yet another approach for RDF.Literal
- we now only the store the lexical form when it's non-canonical
- Literal validation and canonicalization
- a general RDF.Datatype.Test.Case
- also tested datatype implementations for booleans, integers, string and langStrings
- use literal sigils in Inspect implementation of Literals when possible
2017-04-23 23:41:29 +02:00

23 lines
543 B
Elixir

defmodule RDF.Boolean do
use RDF.Datatype, id: RDF.Datatype.NS.XSD.boolean
def convert(value, _) when is_boolean(value), do: value
def convert(value, opts) when is_binary(value) do
with normalized_value = String.downcase(value) do
cond do
normalized_value in ~W[true 1] -> true
normalized_value in ~W[false 0] -> false
true ->
super(value, opts)
end
end
end
def convert(1, _), do: true
def convert(0, _), do: false
def convert(value, opts), do: super(value, opts)
end