class SPARQL::Algebra::Operator::Plus

The SPARQL numeric binary/unary `+` operator.

@example

(+ ?x ?y)
(plus ?x ?y)

@see www.w3.org/TR/xpath-functions/#func-numeric-unary-plus @see www.w3.org/TR/xpath-functions/#func-numeric-add

Constants

NAME

Public Instance Methods

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

Returns the arithmetic sum of the operands, unless there is no `right`.

@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/plus.rb, line 26
def apply(left, right = nil, **options)
  case
  when left.is_a?(RDF::Literal::Numeric) && right.is_a?(RDF::Literal::Numeric)
    left + right
  when left.is_a?(RDF::Literal::Numeric) && right.nil?
    left
  else raise TypeError, "expected two RDF::Literal::Numeric operands, but got #{left.inspect} and #{right.inspect}"
  end
end