class SPARQL::Algebra::Operator::Subtract

The SPARQL numeric `subtract` operator.

(- ?x ?y)
(subtract ?x ?y)

@see www.w3.org/TR/xpath-functions/#func-numeric-subtract

Constants

NAME

Public Instance Methods

apply(left, right, **options) click to toggle source

Returns the arithmetic difference of the operands.

@param [RDF::Literal::Numeric] left

a numeric literal

@param [RDF::Literal::Numeric] right

a numeric literal

@return [RDF::Literal::Numeric] @raise [TypeError] if either operand is not a numeric literal

# File lib/sparql/algebra/operator/subtract.rb, line 23
def apply(left, right, **options)
  case
    when left.is_a?(RDF::Literal::Numeric) && right.is_a?(RDF::Literal::Numeric)
      left - right
    else raise TypeError, "expected two RDF::Literal::Numeric operands, but got #{left.inspect} and #{right.inspect}"
  end
end