Class: SPARQL::Algebra::Operator::Str

Inherits:
Unary show all
Includes:
Evaluatable
Defined in:
lib/sparql/algebra/operator/str.rb

Overview

The SPARQL str operator.

Examples:

(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 Also:

Constant Summary

NAME =
:str

Constants inherited from Unary

Unary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY

Instance Attribute Summary

Attributes inherited from SPARQL::Algebra::Operator

#operands, #options

Instance Method Summary collapse

Methods included from Evaluatable

#evaluate, #memoize

Methods inherited from Unary

#initialize

Methods inherited from SPARQL::Algebra::Operator

arity, #base_uri, base_uri, base_uri=, #boolean, #constant?, #eql?, #evaluatable?, evaluate, #executable?, for, #initialize, #inspect, #operand, #optimize, #prefixes, prefixes, prefixes=, #to_sse, #to_sxp, #variable?

Methods included from Expression

cast, #constant?, #evaluate, for, new, open, #optimize, parse, #to_sse, #variable?

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator::Unary

Instance Method Details

#apply(term) ⇒ RDF::Literal

Returns the string form of the operand.

Raises:

  • (TypeError)

    if the operand is not a literal or IRI



26
27
28
29
30
31
32
# File 'lib/sparql/algebra/operator/str.rb', line 26

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