diff --git a/CHANGELOG.md b/CHANGELOG.md index e7b6fe4..1bf0f2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,9 @@ This project adheres to [Semantic Versioning](http://semver.org/) and ### Fixed -- language literals were not properly unescaped during Turtle parsing +- language literals were not properly unescaped during Turtle parsing +- `RDF.Literal.new/1` can take decimals and infers the datatype `xsd:decimal` + correctly [Compare v0.6.0...HEAD](https://github.com/marcelotto/rdf-ex/compare/v0.6.0...HEAD) diff --git a/lib/rdf/literal.ex b/lib/rdf/literal.ex index 0228c5c..7bfe060 100644 --- a/lib/rdf/literal.ex +++ b/lib/rdf/literal.ex @@ -48,6 +48,7 @@ defmodule RDF.Literal do def new(value) when is_boolean(value), do: RDF.Boolean.new(value) def new(value) when is_integer(value), do: RDF.Integer.new(value) def new(value) when is_float(value), do: RDF.Double.new(value) + def new(%Decimal{} = value), do: RDF.Decimal.new(value) def new(%Date{} = value), do: RDF.Date.new(value) def new(%Time{} = value), do: RDF.Time.new(value) diff --git a/test/unit/literal_test.exs b/test/unit/literal_test.exs index 61ed54c..78a2d3e 100644 --- a/test/unit/literal_test.exs +++ b/test/unit/literal_test.exs @@ -13,6 +13,7 @@ defmodule RDF.LiteralTest do RDF.String => ["foo"], RDF.Integer => [42], RDF.Double => [3.14], + RDF.Decimal => [Decimal.from_float(3.14)], RDF.Boolean => [true, false], } @@ -55,6 +56,8 @@ defmodule RDF.LiteralTest do test "decimal" do assert Literal.new(3.14, datatype: XSD.decimal) == RDF.Decimal.new(3.14) assert Literal.new("3.14", datatype: XSD.decimal) == RDF.Decimal.new("3.14") + assert Literal.new(Decimal.from_float(3.14), datatype: XSD.decimal) == + RDF.Decimal.new(Decimal.from_float(3.14)) end test "string" do