Sha256: ca81459423f676684c459f3c5f822463f19ad01d4a1f24f2a5bed60507229e1d

Contents?: true

Size: 965 Bytes

Versions: 4

Compression:

Stored size: 965 Bytes

Contents

module RDF::N3::Algebra::Log
  ##
  # The subject formula, expressed as N3, gives this string.
  class N3String < RDF::N3::Algebra::ResourceOperator
    NAME = :logN3String
    URI = RDF::N3::Log.n3String

    ##
    # Serializes the subject formula into an N3 string representation.
    #
    # @param [RDF::N3::List] resource
    # @return [RDF::Term]
    def resolve(resource, position: :subject)
      case position
      when :subject
        return nil unless resource.formula?
        as_literal(RDF::N3::Writer.buffer {|w| resource.each {|st| w << st}})
      when :object
        return nil unless resource.literal? || resource.variable?
        resource
      end
    end

    ##
    # Subject must evaluate to a formula and object to a literal.
    #
    # @param [RDF::Term] subject
    # @param [RDF::Term] object
    # @return [Boolean]
    def valid?(subject, object)
      subject.formula? && (object.variable? || object.literal?)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rdf-n3-3.3.0 lib/rdf/n3/algebra/log/n3_string.rb
rdf-n3-3.2.1 lib/rdf/n3/algebra/log/n3_string.rb
rdf-n3-3.2.0 lib/rdf/n3/algebra/log/n3_string.rb
rdf-n3-3.1.2 lib/rdf/n3/algebra/log/n3_string.rb