Class: Redlander::Statement
- Inherits:
-
Object
- Object
- Redlander::Statement
- Defined in:
- lib/redlander/statement.rb
Overview
RDF statement
Instance Method Summary collapse
- #eql?(other_statement) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(source = {}) ⇒ Statement
constructor
Create an RDF statement.
-
#object ⇒ Node?
Object of the statement.
-
#object=(node) ⇒ void
Set the object of the statement.
-
#predicate ⇒ Node?
Predicate of the statement.
-
#predicate=(node) ⇒ void
Set the predicate of the statement.
- #rdf_statement ⇒ Object private
-
#subject ⇒ Node?
Subject of the statment.
-
#subject=(node) ⇒ void
Set the subject of the statement.
- #to_s ⇒ Object
Constructor Details
#initialize(source = {}) ⇒ Statement
Create an RDF statement.
42 43 44 45 46 |
# File 'lib/redlander/statement.rb', line 42 def initialize(source = {}) # If FFI::Pointer is passed, wrap it instantly, # because it can be freed outside before it is used here. @source = source.is_a?(FFI::Pointer) ? wrap(source) : source end |
Instance Method Details
#eql?(other_statement) ⇒ Boolean Also known as: ==
111 112 113 114 115 |
# File 'lib/redlander/statement.rb', line 111 def eql?(other_statement) subject == other_statement.subject && predicate == other_statement.predicate && object == other_statement.object end |
#hash ⇒ Object
118 119 120 |
# File 'lib/redlander/statement.rb', line 118 def hash self.class.hash + to_s.hash end |
#object ⇒ Node?
Object of the statement.
75 76 77 78 79 80 81 82 |
# File 'lib/redlander/statement.rb', line 75 def object if instance_variable_defined?(:@object) @object else rdf_node = Redland.librdf_statement_get_object(rdf_statement) @object = rdf_node.null? ? nil : Node.new(rdf_node) end end |
#object=(node) ⇒ void
This method returns an undefined value.
Set the object of the statement
106 107 108 109 |
# File 'lib/redlander/statement.rb', line 106 def object=(node) Redland.librdf_statement_set_object(rdf_statement, rdf_node_from(node)) @object = node end |
#predicate ⇒ Node?
Predicate of the statement.
63 64 65 66 67 68 69 70 |
# File 'lib/redlander/statement.rb', line 63 def predicate if instance_variable_defined?(:@predicate) @predicate else rdf_node = Redland.librdf_statement_get_predicate(rdf_statement) @predicate = rdf_node.null? ? nil : Node.new(rdf_node) end end |
#predicate=(node) ⇒ void
This method returns an undefined value.
Set the predicate of the statement
97 98 99 100 |
# File 'lib/redlander/statement.rb', line 97 def predicate=(node) Redland.librdf_statement_set_predicate(rdf_statement, rdf_node_from(node)) @predicate = node end |
#rdf_statement ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/redlander/statement.rb', line 14 def rdf_statement unless instance_variable_defined?(:@rdf_statement) @rdf_statement = case @source when FFI::Pointer @source when Hash # Create a new statement from nodes s = rdf_node_from(@source[:subject]) p = rdf_node_from(@source[:predicate]) o = rdf_node_from(@source[:object]) Redland.librdf_new_statement_from_nodes(Redlander.rdf_world, s, p, o) else raise NotImplementedError, "Cannot create Statement from '#{@source.inspect}'" end raise RedlandError, "Failed to create a new statement" if @rdf_statement.null? ObjectSpace.define_finalizer(self, self.class.send(:finalize_statement, @rdf_statement)) end @rdf_statement end |
#subject ⇒ Node?
Subject of the statment.
51 52 53 54 55 56 57 58 |
# File 'lib/redlander/statement.rb', line 51 def subject if instance_variable_defined?(:@subject) @subject else rdf_node = Redland.librdf_statement_get_subject(rdf_statement) @subject = rdf_node.null? ? nil : Node.new(rdf_node) end end |
#subject=(node) ⇒ void
This method returns an undefined value.
Set the subject of the statement
88 89 90 91 |
# File 'lib/redlander/statement.rb', line 88 def subject=(node) Redland.librdf_statement_set_subject(rdf_statement, rdf_node_from(node)) @subject = node end |
#to_s ⇒ Object
122 123 124 |
# File 'lib/redlander/statement.rb', line 122 def to_s Redland.librdf_statement_to_string(rdf_statement) end |