ruby-rdf/spira

View on GitHub
lib/spira/types/int.rb

Summary

Maintainability
A
15 mins
Test Coverage
module Spira::Types

  ##
  # A {Spira::Type} for integer values.  Values will be associated with the
  # `XSD.int` type.
  #
  # A {Spira::Resource} property can reference this type as
  # `Spira::Types::Int`, `Int`, or `XSD.int`.
  #
  # @see Spira::Type
  # @see https://ruby-rdf.github.io/rdf/RDF/Literal.html
  class Int

    include Spira::Type

    def self.unserialize(value)
      value.object.to_i
    end

    def self.serialize(value)
      RDF::Literal.new(value, datatype: XSD.int)
    end

    register_alias RDF::XSD.int

  end
end