Class: RDF::N3::Algebra::Math::Remainder

Inherits:
ListOperator
  • Object
show all
Defined in:
lib/rdf/n3/algebra/math/remainder.rb

Overview

The subject is a pair of integers. The object is calculated by dividing the first number of the pair by the second and taking the remainder.

Constant Summary collapse

NAME =
:mathRemainder
URI =
RDF::N3::Math.remainder

Instance Attribute Summary

Attributes included from Enumerable

#existentials, #universals

Instance Method Summary collapse

Methods inherited from ListOperator

#as_literal, #execute, #input_operand

Methods included from Builtin

#each, #evaluate, #hash, #input_operand, #rank, #to_uri

Instance Method Details

#resolve(list) ⇒ RDF::Term

The math:remainder operator takes a pair of strings or numbers and calculates their remainder.

Parameters:

Returns:

See Also:

  • ListOperator#evaluate


16
17
18
# File 'lib/rdf/n3/algebra/math/remainder.rb', line 16

def resolve(list)
  list.to_a.map(&:as_number).reduce(&:%)
end

#validate(list) ⇒ Boolean

The list argument must be a pair of literals.

Parameters:

Returns:

  • (Boolean)

See Also:

  • ListOperator#validate


26
27
28
29
30
31
32
33
# File 'lib/rdf/n3/algebra/math/remainder.rb', line 26

def validate(list)
  if super && list.all? {|li| li.is_a?(RDF::Literal) && li.as_number.is_a?(RDF::Literal::Integer)} && list.length == 2
    true
  else
    log_error(NAME) {"list is not a pair of integers: #{list.to_sxp}"}
    false
  end
end