Sha256: ca984cd296871c7e9c5f89435f8a98ac5569a7c89f98d81307efd9ce5353280c

Contents?: true

Size: 1.03 KB

Versions: 31

Compression:

Stored size: 1.03 KB

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL `str` operator.
    #
    # @example
    #   (prefix ((xsd: <http://www.w3.org/2001/XMLSchema#>)
    #            (: <http://example.org/things#>))
    #     (project (?x ?v)
    #       (filter (= (str ?v) "1")
    #         (bgp (triple ?x :p ?v)))))
    #
    # @see http://www.w3.org/TR/rdf-sparql-query/#func-str
    class Str < Operator::Unary
      include Evaluatable

      NAME = :str

      ##
      # Returns the string form of the operand.
      #
      # @param  [RDF::Literal, RDF::URI] term
      #   a literal or IRI
      # @return [RDF::Literal] a simple literal
      # @raise  [TypeError] if the operand is not a literal or IRI
      def apply(term)
        case term
          when RDF::Literal then RDF::Literal(term.value)
          when RDF::URI     then RDF::Literal(term.to_s)
          else raise TypeError, "expected an RDF::Literal or RDF::URI, but got #{term.inspect}"
        end
      end
    end # Str
  end # Operator
end; end # SPARQL::Algebra

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
sparql-1.99.1 lib/sparql/algebra/operator/str.rb
sparql-1.1.9.1 lib/sparql/algebra/operator/str.rb
sparql-1.99.0 lib/sparql/algebra/operator/str.rb
sparql-1.1.9 lib/sparql/algebra/operator/str.rb
sparql-1.1.8 lib/sparql/algebra/operator/str.rb
sparql-1.1.7 lib/sparql/algebra/operator/str.rb
sparql-1.1.6 lib/sparql/algebra/operator/str.rb
sparql-1.1.5 lib/sparql/algebra/operator/str.rb
sparql-1.1.4 lib/sparql/algebra/operator/str.rb
sparql-1.1.3 lib/sparql/algebra/operator/str.rb
sparql-1.1.2.1 lib/sparql/algebra/operator/str.rb
sparql-1.1.2 lib/sparql/algebra/operator/str.rb
sparql-1.1.1 lib/sparql/algebra/operator/str.rb
sparql-1.1.0 lib/sparql/algebra/operator/str.rb
sparql-1.1.0p0 lib/sparql/algebra/operator/str.rb
sparql-1.0.8 lib/sparql/algebra/operator/str.rb
sparql-1.0.7 lib/sparql/algebra/operator/str.rb
sparql-1.0.6 lib/sparql/algebra/operator/str.rb
sparql-1.0.5 lib/sparql/algebra/operator/str.rb
sparql-1.0.4 lib/sparql/algebra/operator/str.rb