Sha256: fc3c47820134bc8b0a301a3f7ed28b77c87e145c9eee476a68302697a9a4a208

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

module RDF::N3::Algebra::Math
  ##
  # True iff the subject is a string representation of a number which  is less than the number of which the object is a string representation.
  #
  # @see https://www.w3.org/TR/xpath-functions/#func-numeric-less-than
  class LessThan < RDF::N3::Algebra::ResourceOperator
    NAME = :mathLessThan
    URI = RDF::N3::Math.lessThan

    ##
    # Resolves inputs as numbers.
    #
    # @param [RDF::Term] resource
    # @param [:subject, :object] position
    # @return [RDF::Term]
    # @see RDF::N3::ResourceOperator#evaluate
    def resolve(resource, position:)
      resource.as_number if resource.term?
    end

    # Both subject and object are inputs.
    def input_operand
      RDF::N3::List.new(values: operands)
    end

    ##
    # Returns TRUE if `term1` is less than `term2`.
    #
    # @param  [RDF::Term] term1
    #   an RDF term
    # @param  [RDF::Term] term2
    #   an RDF term
    # @return [RDF::Literal::Boolean] `true` or `false`
    # @raise  [TypeError] if either operand is not an RDF term or operands are not comperable
    #
    # @see RDF::Term#==
    def apply(term1, term2)
      RDF::Literal(term1 < term2)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rdf-n3-3.3.0 lib/rdf/n3/algebra/math/less_than.rb
rdf-n3-3.2.1 lib/rdf/n3/algebra/math/less_than.rb
rdf-n3-3.2.0 lib/rdf/n3/algebra/math/less_than.rb
rdf-n3-3.1.2 lib/rdf/n3/algebra/math/less_than.rb