Class: RDF::N3::Algebra::Math::Quotient
- Inherits:
-
ListOperator
- Object
- SPARQL::Algebra::Operator::Binary
- ListOperator
- RDF::N3::Algebra::Math::Quotient
- Defined in:
- lib/rdf/n3/algebra/math/quotient.rb
Overview
The subject is a pair of numbers. The object is calculated by dividing the first number of the pair by the second.
Constant Summary collapse
Instance Attribute Summary
Attributes included from Enumerable
Instance Method Summary collapse
-
#resolve(list) ⇒ RDF::Term
The math:quotient operator takes a pair of strings or numbers and calculates their quotient.
-
#validate(list) ⇒ Boolean
The list argument must be a pair of literals.
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:quotient operator takes a pair of strings or numbers and calculates their quotient.
17 18 19 |
# File 'lib/rdf/n3/algebra/math/quotient.rb', line 17 def resolve(list) list.to_a.map(&:as_number).reduce(&:/) end |
#validate(list) ⇒ Boolean
The list argument must be a pair of literals.
27 28 29 30 31 32 33 34 |
# File 'lib/rdf/n3/algebra/math/quotient.rb', line 27 def validate(list) if super && list.all? {|le| le.is_a?(RDF::Literal)} && list.length == 2 true else log_error(NAME) {"list is not a pair of literals: #{list.to_sxp}"} false end end |