Sha256: f42053aace7de7e6d96cc5b7394bed5b1f260a7df39776addb0f70182d52345f

Contents?: true

Size: 851 Bytes

Versions: 5

Compression:

Stored size: 851 Bytes

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL numeric unary `-` (negation) operator.
    #
    # @example
    #   (- ?x)
    #   (negate ?x)
    #
    # @see https://www.w3.org/TR/xpath-functions/#func-numeric-unary-minus
    class Negate < Operator::Unary
      include Evaluatable

      NAME = [:-, :negate]

      ##
      # Returns the operand with its sign reversed.
      #
      # @param  [RDF::Literal::Numeric] term
      #   a numeric literal
      # @return [RDF::Literal::Numeric]
      # @raise  [TypeError] if the operand is not a numeric literal
      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
    end # Negate
  end # Operator
end; end # SPARQL::Algebra

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sparql-3.1.6 lib/sparql/algebra/operator/negate.rb
sparql-3.1.5 lib/sparql/algebra/operator/negate.rb
sparql-3.1.4 lib/sparql/algebra/operator/negate.rb
sparql-3.1.3 lib/sparql/algebra/operator/negate.rb
sparql-3.1.2 lib/sparql/algebra/operator/negate.rb