Class: RDF::Raptor::FFI::V2::Statement
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- RDF::Raptor::FFI::V2::Statement
- Includes:
- RDF::Raptor::FFI
- Defined in:
- lib/rdf/raptor/ffi/v2/statement.rb
Overview
Constant Summary
Constants included from RDF::Raptor::FFI
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#free
(also: #release)
Releases
libraptor
memory associated with this structure. -
#initialize(ptr = nil, factory = nil) ⇒ Statement
constructor
A new instance of Statement.
- #object ⇒ RDF::Term
-
#object=(value)
Sets the object term from an
RDF::Term
. - #predicate ⇒ RDF::URI
-
#predicate=(uri)
Sets the predicate term from an
RDF::URI
. - #reset!
- #subject ⇒ RDF::Resource
-
#subject=(resource)
Sets the subject term from an
RDF::Resource
. - #to_quad ⇒ Array(RDF::Resource, RDF::URI, RDF::Term, nil)
- #to_rdf ⇒ RDF::Statement
- #to_triple ⇒ Array(RDF::Resource, RDF::URI, RDF::Term)
Methods included from RDF::Raptor::FFI
Constructor Details
#initialize(ptr = nil, factory = nil) ⇒ Statement
Returns a new instance of Statement.
16 17 18 19 |
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 16 def initialize(ptr = nil, factory = nil) super(ptr) @factory = factory if factory end |
Instance Attribute Details
#graph_name ⇒ RDF::Resource
33 34 35 |
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 33 def graph_name @graph_name end |
#id ⇒ Object
30 31 32 |
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 30 def id @id end |
Instance Method Details
#free Also known as: release
This method returns an undefined value.
Releases libraptor
memory associated with this structure.
137 138 139 140 |
# 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 |
#object ⇒ RDF::Term
79 80 81 |
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 79 def object @object ||= V2::Term.new(self[:object], @factory).value end |
#object=(value)
This method returns an undefined value.
Sets the object term from an RDF::Term
.
The value must be one of RDF::Resource
or RDF::Literal
.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# 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 ⇒ RDF::URI
61 62 63 |
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 61 def predicate @predicate ||= V2::Term.new(self[:predicate], @factory).value end |
#predicate=(uri)
This method returns an undefined value.
Sets the predicate term from an RDF::URI
.
70 71 72 73 74 75 |
# 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 |
#reset!
This method returns an undefined value.
129 130 131 |
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 129 def reset! @subject = @predicate = @object = @graph_name = nil end |
#subject ⇒ RDF::Resource
37 38 39 |
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 37 def subject @subject ||= V2::Term.new(self[:subject], @factory).value end |
#subject=(resource)
This method returns an undefined value.
Sets the subject term from an RDF::Resource
.
46 47 48 49 50 51 52 53 54 55 56 57 |
# 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 ⇒ Array(RDF::Resource, RDF::URI, RDF::Term, nil)
117 118 119 |
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 117 def to_quad [subject, predicate, object, graph_name] end |
#to_rdf ⇒ RDF::Statement
123 124 125 |
# 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 ⇒ Array(RDF::Resource, RDF::URI, RDF::Term)
110 111 112 |
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 110 def to_triple [subject, predicate, object] end |