Add length, minLength and maxLength XSD datatype facets
This commit is contained in:
parent
2c4b5f604a
commit
22c2aaa1af
6 changed files with 47 additions and 0 deletions
|
@ -9,6 +9,25 @@ defmodule RDF.XSD.String do
|
||||||
name: "string",
|
name: "string",
|
||||||
id: RDF.Utils.Bootstrapping.xsd_iri("string")
|
id: RDF.Utils.Bootstrapping.xsd_iri("string")
|
||||||
|
|
||||||
|
def_applicable_facet RDF.XSD.Facets.MinLength
|
||||||
|
def_applicable_facet RDF.XSD.Facets.MaxLength
|
||||||
|
def_applicable_facet RDF.XSD.Facets.Length
|
||||||
|
|
||||||
|
@doc false
|
||||||
|
def min_length_conform?(min_length, value, _lexical) do
|
||||||
|
String.length(value) >= min_length
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
|
def max_length_conform?(max_length, value, _lexical) do
|
||||||
|
String.length(value) <= max_length
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
|
def length_conform?(length, value, _lexical) do
|
||||||
|
String.length(value) == length
|
||||||
|
end
|
||||||
|
|
||||||
@impl RDF.XSD.Datatype
|
@impl RDF.XSD.Datatype
|
||||||
@spec lexical_mapping(String.t(), Keyword.t()) :: valid_value
|
@spec lexical_mapping(String.t(), Keyword.t()) :: valid_value
|
||||||
def lexical_mapping(lexical, _), do: to_string(lexical)
|
def lexical_mapping(lexical, _), do: to_string(lexical)
|
||||||
|
|
3
lib/rdf/xsd/facets/length.ex
Normal file
3
lib/rdf/xsd/facets/length.ex
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule RDF.XSD.Facets.Length do
|
||||||
|
use RDF.XSD.Facet, name: :length, type: integer
|
||||||
|
end
|
3
lib/rdf/xsd/facets/max_length.ex
Normal file
3
lib/rdf/xsd/facets/max_length.ex
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule RDF.XSD.Facets.MaxLength do
|
||||||
|
use RDF.XSD.Facet, name: :max_length, type: integer
|
||||||
|
end
|
3
lib/rdf/xsd/facets/min_length.ex
Normal file
3
lib/rdf/xsd/facets/min_length.ex
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule RDF.XSD.Facets.MinLength do
|
||||||
|
use RDF.XSD.Facet, name: :min_length, type: integer
|
||||||
|
end
|
|
@ -1,4 +1,13 @@
|
||||||
defmodule RDF.TestDatatypes do
|
defmodule RDF.TestDatatypes do
|
||||||
|
defmodule Initials do
|
||||||
|
use RDF.XSD.Datatype.Restriction,
|
||||||
|
name: "initials",
|
||||||
|
id: "http://example.com/initials",
|
||||||
|
base: RDF.XSD.String
|
||||||
|
|
||||||
|
def_facet_constraint RDF.XSD.Facets.Length, 2
|
||||||
|
end
|
||||||
|
|
||||||
defmodule Age do
|
defmodule Age do
|
||||||
use RDF.XSD.Datatype.Restriction,
|
use RDF.XSD.Datatype.Restriction,
|
||||||
name: "age",
|
name: "age",
|
||||||
|
|
|
@ -3,6 +3,16 @@ defmodule RDF.XSD.StringTest do
|
||||||
datatype: RDF.XSD.String,
|
datatype: RDF.XSD.String,
|
||||||
name: "string",
|
name: "string",
|
||||||
primitive: true,
|
primitive: true,
|
||||||
|
applicable_facets: [
|
||||||
|
RDF.XSD.Facets.MinLength,
|
||||||
|
RDF.XSD.Facets.MaxLength,
|
||||||
|
RDF.XSD.Facets.Length,
|
||||||
|
],
|
||||||
|
facets: %{
|
||||||
|
max_length: nil,
|
||||||
|
min_length: nil,
|
||||||
|
length: nil
|
||||||
|
},
|
||||||
valid: %{
|
valid: %{
|
||||||
# input => { value, lexical, canonicalized }
|
# input => { value, lexical, canonicalized }
|
||||||
"foo" => {"foo", nil, "foo"},
|
"foo" => {"foo", nil, "foo"},
|
||||||
|
|
Loading…
Reference in a new issue