Sha256: 2934506f5fcedbf3ba8a4416d337bc99f48d0b35169a0157d044220a41dec2fa

Contents?: true

Size: 1.32 KB

Versions: 17

Compression:

Stored size: 1.32 KB

Contents

require 'uri'

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL logical `abs` operator.
    #
    # @example
    #   (encode_for_uri ?x)
    #
    # @see http://www.w3.org/TR/sparql11-query/#func-encode
    # @see http://www.w3.org/TR/xpath-functions/#func-abs
    class EncodeForURI < Operator::Unary
      include Evaluatable

      NAME = :encode_for_uri

      ##
      # The ENCODE_FOR_URI function corresponds to the XPath fn:encode-for-uri function. It returns a simple literal with the lexical form obtained from the lexical form of its input after translating reserved characters according to the fn:encode-for-uri function.
      #
      # @example
      #     encode_for_uri("Los Angeles")	"Los%20Angeles"
      #     encode_for_uri("Los Angeles"@en)	"Los%20Angeles"
      #     encode_for_uri("Los Angeles"^^xsd:string)	"Los%20Angeles"
      #
      # @param  [RDF::Literal] operand
      #   the operand
      # @return [RDF::Literal] literal of same type
      # @raise  [TypeError] if the operand is not a literal value
      def apply(operand)
        case operand
          when RDF::Literal then RDF::Literal(::URI.encode(operand.to_s))
          else raise TypeError, "expected an RDF::Literal, but got #{operand.inspect}"
        end
      end
    end # EncodeForURI
  end # Operator
end; end # SPARQL::Algebra

Version data entries

17 entries across 17 versions & 1 rubygems

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