class RDF::Raptor::FFI::V2::Statement

@see librdf.org/raptor/api-1.4/raptor-section-triples.html

Attributes

graph_name[RW]

@return [RDF::Resource]

id[RW]

@return [Object]

Public Class Methods

new(ptr = nil, factory = nil) click to toggle source

@param [FFI::Pointer] ptr @param [#create_node] factory

Calls superclass method
# File lib/rdf/raptor/ffi/v2/statement.rb, line 16
def initialize(ptr = nil, factory = nil)
  super(ptr)
  @factory = factory if factory
end

Public Instance Methods

free() click to toggle source

Releases ‘libraptor` memory associated with this structure.

@return [void]

# File lib/rdf/raptor/ffi/v2/statement.rb, line 137
def free
  V2.raptor_free_statement(self)
  @subject = @predicate = @object = nil # Allow GC to start
end
Also aliased as: release
object() click to toggle source

@return [RDF::Term]

# File lib/rdf/raptor/ffi/v2/statement.rb, line 79
def object
  @object ||= V2::Term.new(self[:object], @factory).value
end
object=(value) click to toggle source

Sets the object term from an ‘RDF::Term`.

The value must be one of ‘RDF::Resource` or `RDF::Literal`.

@param [RDF::Term] value @return [void]

# File lib/rdf/raptor/ffi/v2/statement.rb, line 90
def object=(value)
  @object = nil
  case value
    when RDF::Node
      self[:object] = V2.raptor_new_term_from_blank(V2.world, value.id.to_s)
    when RDF::URI
      self[:object] = V2.raptor_new_term_from_uri_string(V2.world, value.to_s)
    when RDF::Literal
      self[:object] = V2.raptor_new_term_from_literal(V2.world, value.to_s,
        value.datatype? ? V2.raptor_new_uri(V2.world, value.datatype.to_s) : nil,
        value.language? ? value.language.to_s : nil)
    else
      raise ArgumentError, "object term must be an RDF::Node, RDF::URI, or RDF::Literal"
  end
  @object = value
end
predicate() click to toggle source

@return [RDF::URI]

# File lib/rdf/raptor/ffi/v2/statement.rb, line 61
def predicate
  @predicate ||= V2::Term.new(self[:predicate], @factory).value
end
predicate=(uri) click to toggle source

Sets the predicate term from an ‘RDF::URI`.

@param [RDF::URI] uri @return [void]

# File lib/rdf/raptor/ffi/v2/statement.rb, line 70
def predicate=(uri)
  @predicate = nil
  raise ArgumentError, "predicate term must be an RDF::URI" unless uri.is_a?(RDF::URI)
  self[:predicate] = V2.raptor_new_term_from_uri_string(V2.world, uri.to_s)
  @predicate = uri
end
release() click to toggle source

Releases ‘libraptor` memory associated with this structure.

@return [void]

# File lib/rdf/raptor/ffi/v2/statement.rb, line 25
def release
  V2.raptor_free_statement(ptr) unless ptr.null?
end
reset!() click to toggle source

@return [void]

# File lib/rdf/raptor/ffi/v2/statement.rb, line 129
def reset!
  @subject = @predicate = @object = @graph_name = nil
end
subject() click to toggle source

@return [RDF::Resource]

# File lib/rdf/raptor/ffi/v2/statement.rb, line 37
def subject
  @subject ||= V2::Term.new(self[:subject], @factory).value
end
subject=(resource) click to toggle source

Sets the subject term from an ‘RDF::Resource`.

@param [RDF::Resource] resource @return [void]

# File lib/rdf/raptor/ffi/v2/statement.rb, line 46
def subject=(resource)
  @subject = nil
  case resource
    when RDF::Node
      self[:subject] = V2.raptor_new_term_from_blank(V2.world, resource.id.to_s)
    when RDF::URI
      self[:subject] = V2.raptor_new_term_from_uri_string(V2.world, resource.to_s)
    else
      raise ArgumentError, "subject term must be an RDF::Node or RDF::URI"
  end
  @subject = resource
end
to_quad() click to toggle source

@return [Array(RDF::Resource, RDF::URI, RDF::Term, nil)] @see RDF::Statement#to_quad

# File lib/rdf/raptor/ffi/v2/statement.rb, line 117
def to_quad
  [subject, predicate, object, graph_name]
end
to_rdf() click to toggle source

@return [RDF::Statement]

# File lib/rdf/raptor/ffi/v2/statement.rb, line 123
def to_rdf
  RDF::Statement.new(subject, predicate, object, graph_name: graph_name)
end
to_triple() click to toggle source

@return [Array(RDF::Resource, RDF::URI, RDF::Term)] @see RDF::Statement#to_triple

# File lib/rdf/raptor/ffi/v2/statement.rb, line 110
def to_triple
  [subject, predicate, object]
end