Sha256: 0f2ac28d0232c877304d3e1536a4d2c2c4b9033d4f73982ddb723301920ecb46

Contents?: true

Size: 813 Bytes

Versions: 4

Compression:

Stored size: 813 Bytes

Contents

module RDF::N3::Algebra::Math
  ##
  # The object is calculated as the subject downwards to a whole number.
  #
  # @see https://www.w3.org/TR/xpath-functions/#func-floor
  class Floor < RDF::N3::Algebra::ResourceOperator
    NAME = :mathFloor
    URI = RDF::N3::Math.floor

    ##
    # The math:floor operator takes string or number and calculates its floor.
    #
    # @param [RDF::Term] resource
    # @param [:subject, :object] position
    # @return [RDF::Term]
    # @see RDF::N3::ResourceOperator#evaluate
    def resolve(resource, position:)
      case position
      when :subject
        return nil unless resource.literal?
        RDF::Literal(resource.as_number.floor)
      when :object
        return nil unless resource.literal? || resource.variable?
        resource
      end
    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/floor.rb
rdf-n3-3.2.1 lib/rdf/n3/algebra/math/floor.rb
rdf-n3-3.2.0 lib/rdf/n3/algebra/math/floor.rb
rdf-n3-3.1.2 lib/rdf/n3/algebra/math/floor.rb