Sha256: 581904fd82633f876af85bb33a8e1a493e85c4fad690916a3506cde8f90a554b

Contents?: true

Size: 846 Bytes

Versions: 12

Compression:

Stored size: 846 Bytes

Contents

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

      NAME = [:-, :minus]

      ##
      # 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 # Minus
  end # Operator
end; end # SPARQL::Algebra

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
sparql-1.0.8 lib/sparql/algebra/operator/minus.rb
sparql-1.0.7 lib/sparql/algebra/operator/minus.rb
sparql-1.0.6 lib/sparql/algebra/operator/minus.rb
sparql-1.0.5 lib/sparql/algebra/operator/minus.rb
sparql-1.0.4 lib/sparql/algebra/operator/minus.rb
sparql-1.0.3 lib/sparql/algebra/operator/minus.rb
sparql-1.0.2 lib/sparql/algebra/operator/minus.rb
sparql-1.0.1 lib/sparql/algebra/operator/minus.rb
sparql-1.0.0 lib/sparql/algebra/operator/minus.rb
sparql-0.3.3 lib/sparql/algebra/operator/minus.rb
sparql-0.3.2 lib/sparql/algebra/operator/minus.rb
sparql-0.3.1 lib/sparql/algebra/operator/minus.rb