Class: RDF::N3::Algebra::Log::DtLit

Inherits:
RDF::N3::Algebra::ListOperator show all
Defined in:
lib/rdf/n3/algebra/log/dtlit.rb

Overview

Takes a list of a string and an IRI and creates a datatyped literal.

Constant Summary collapse

NAME =
:dtlit
URI =
RDF::N3::Log.dtlit

Instance Attribute Summary

Attributes included from Enumerable

#existentials, #universals

Instance Method Summary collapse

Methods inherited from RDF::N3::Algebra::ListOperator

#as_literal, #execute, #input_operand

Methods included from Builtin

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

Instance Method Details

#resolve(resource, position: :subject) ⇒ RDF::Term

Reads the subject into the object.

Returns nil if resource does not validate, given its position

Parameters:

Returns:



15
16
17
18
19
20
21
22
23
# File 'lib/rdf/n3/algebra/log/dtlit.rb', line 15

def resolve(resource, position: :subject)
  case position
  when :subject
    RDF::Literal(as_literal(resource.first).to_s, datatype: resource.last)
  when :object
    return nil unless resource.literal? || resource.variable?
    resource
  end
end

#validate(list) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rdf/n3/algebra/log/dtlit.rb', line 25

def validate(list)
  if super(list)
    if list.length != 2
      log_error(NAME) {"operand is not a list with two elements: #{list.to_sxp}"}
      false
    elsif !list.last.uri?
      log_error(NAME) {"second component of subject must be an IRI: #{list.last.to_sxp}"}
      false
    else
      true
    end
  else
    false
  end
end