Sha256: 7b0e2db248a6a7d6978a1d07c908a6883d996b96bdac3031254787ab21204030

Contents?: true

Size: 1.05 KB

Versions: 5

Compression:

Stored size: 1.05 KB

Contents

require 'securerandom'

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL `uuid` function.
    #
    # @example
    #     (prefix ((: <http://example.org/>)
    #              (xsd: <http://www.w3.org/2001/XMLSchema#>))
    #       (project (?length)
    #         (extend ((?length (strlen (str ?uuid))))
    #           (filter (&& (isIRI ?uuid) (regex (str ?uuid) "^urn:uuid:[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$" "i"))
    #             (extend ((?uuid (uuid)))
    #               (bgp))))))
    #
    # @see https://www.w3.org/TR/sparql11-query/#func-uuid
    class UUID < Operator::Nullary
      include Evaluatable

      NAME = :uuid

      ##
      # Return a fresh IRI from the UUID URN scheme. Each call of UUID() returns a different UUID. It must not be the "nil" UUID (all zeroes). The variant and version of the UUID is implementation dependent.
      #
      # @return [RDF::URI]
      def apply
        RDF::URI("urn:uuid:#{SecureRandom.uuid}")
      end
    end # UUID
  end # Operator
end; end # SPARQL::Algebra

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sparql-3.1.6 lib/sparql/algebra/operator/uuid.rb
sparql-3.1.5 lib/sparql/algebra/operator/uuid.rb
sparql-3.1.4 lib/sparql/algebra/operator/uuid.rb
sparql-3.1.3 lib/sparql/algebra/operator/uuid.rb
sparql-3.1.2 lib/sparql/algebra/operator/uuid.rb