Sha256: 17d0cf6ff28b89a12bf16a24c43ededb135d3bd52d936d3035c5e5a78b35e292

Contents?: true

Size: 1.25 KB

Versions: 11

Compression:

Stored size: 1.25 KB

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL logical `round` operator.
    #
    # Returns the number with no fractional part that is closest to the argument. If there are two such numbers, then the one that is closest to positive infinity is returned. An error is raised if `arg` is not a numeric value.
    # 
    # @example
    #   (round ?x)
    #
    # @see http://www.w3.org/TR/sparql11-query/#func-round
    # @see http://www.w3.org/TR/xpath-functions/#func-round
    class Round < Operator::Unary
      include Evaluatable

      NAME = [:round]

      ##
      # Returns the number with no fractional part that is closest to the argument. If there are two such numbers, then the one that is closest to positive infinity is returned. 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.round
          else raise TypeError, "expected an RDF::Literal::Numeric, but got #{operand.inspect}"
        end
      end
    end # Round
  end # Operator
end; end # SPARQL::Algebra

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sparql-3.1.0 lib/sparql/algebra/operator/round.rb
sparql-3.0.2 lib/sparql/algebra/operator/round.rb
sparql-3.0.1 lib/sparql/algebra/operator/round.rb
sparql-3.0.0 lib/sparql/algebra/operator/round.rb
sparql-2.2.2 lib/sparql/algebra/operator/round.rb
sparql-2.2.1 lib/sparql/algebra/operator/round.rb
sparql-2.2.0 lib/sparql/algebra/operator/round.rb
sparql-2.1.0 lib/sparql/algebra/operator/round.rb
sparql-2.0.0 lib/sparql/algebra/operator/round.rb
sparql-2.0.0.beta2 lib/sparql/algebra/operator/round.rb
sparql-2.0.0.beta1 lib/sparql/algebra/operator/round.rb