class SPARQL::Algebra::Operator::EncodeForURI

The SPARQL logical `abs` operator.

@example

(encode_for_uri ?x)

@see www.w3.org/TR/sparql11-query/#func-encode @see www.w3.org/TR/xpath-functions/#func-abs

Constants

NAME

Public Instance Methods

apply(operand, **options) click to toggle source

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

# File lib/sparql/algebra/operator/encode_for_uri.rb, line 30
def apply(operand, **options)
  case operand
    when RDF::Literal then RDF::Literal(CGI.escape(operand.to_s))
    else raise TypeError, "expected an RDF::Literal, but got #{operand.inspect}"
  end
end