Sha256: 698e90abd68d3c11250f378ca3a03f37520945bc36097b7f71efa4809ad3cc32

Contents?: true

Size: 839 Bytes

Versions: 4

Compression:

Stored size: 839 Bytes

Contents

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

      NAME = [:+, :plus]

      ##
      # Returns the operand with its sign unchanged.
      #
      # @param  [RDF::Literal::Numeric] numeric
      #   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 # Plus
  end # Operator
end; end # SPARQL::Algebra

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sparql-0.3.0 lib/sparql/algebra/operator/plus.rb
sparql-0.1.1 lib/sparql/algebra/operator/plus.rb
sparql-0.1.0 lib/sparql/algebra/operator/plus.rb
sparql-0.0.2 lib/sparql/algebra/operator/plus.rb