Class: SPARQL::Algebra::Operator::Negate
- Includes:
- Evaluatable
- Defined in:
- lib/sparql/algebra/operator/negate.rb
Overview
The SPARQL numeric unary - (negation) operator.
[118] UnaryExpression ::= ... | '-' PrimaryExpression
Constant Summary collapse
- NAME =
[:-, :negate]
Instance Method Summary collapse
-
#apply(term, **options) ⇒ RDF::Literal::Numeric
Returns the operand with its sign reversed.
-
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
Methods included from Evaluatable
#evaluate, #memoize, #replace_aggregate!, #replace_vars!
Instance Method Details
#apply(term, **options) ⇒ RDF::Literal::Numeric
Returns the operand with its sign reversed.
34 35 36 37 38 39 |
# File 'lib/sparql/algebra/operator/negate.rb', line 34 def apply(term, **) case term when RDF::Literal::Numeric then -term else raise TypeError, "expected an RDF::Literal::Numeric, but got #{term.inspect}" end end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
46 47 48 |
# File 'lib/sparql/algebra/operator/negate.rb', line 46 def to_sparql(**) "(-#{operands.to_sparql(**)})" end |