Sha256: 1a68f77e16aaba4f19b9f84e2a10519d8dfb01edab7b724a825428bea2f15397

Contents?: true

Size: 906 Bytes

Versions: 5

Compression:

Stored size: 906 Bytes

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL logical `abs` operator.
    #
    # @example
    #   (abs ?x)
    #
    # @see https://www.w3.org/TR/sparql11-query/#func-abs
    # @see https://www.w3.org/TR/xpath-functions/#func-abs
    class Abs < Operator::Unary
      include Evaluatable

      NAME = [:abs]

      ##
      # Returns the absolute value of `arg`. An error is raised if `arg` is not a numeric value.
      # 
      # @param  [RDF::Literal] operand
      #   the operand
      # @return [RDF::Literal] literal of same type
      # @raise  [TypeError] if the operand is not a numeric value
      def apply(operand)
        case operand
          when RDF::Literal::Numeric then operand.abs
          else raise TypeError, "expected an RDF::Literal::Numeric, but got #{operand.inspect}"
        end
      end
    end # Abs
  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/abs.rb
sparql-3.1.5 lib/sparql/algebra/operator/abs.rb
sparql-3.1.4 lib/sparql/algebra/operator/abs.rb
sparql-3.1.3 lib/sparql/algebra/operator/abs.rb
sparql-3.1.2 lib/sparql/algebra/operator/abs.rb