Class: RDF::Triple
- Inherits:
-
Object
- Object
- RDF::Triple
- Defined in:
- lib/rdf/triple.rb
Overview
A triple.
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
the object of this triple.
-
#predicate ⇒ Object
readonly
the predicate of this triple.
-
#subject ⇒ Object
readonly
the subject of this triple.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(o) ⇒ Object
(also: #eql?)
Returns true if
o
is a Triple with the samesubject
,object
, andpredicate
. -
#hash ⇒ Object
Returns a hash value for this Triple.
-
#initialize(subject, predicate, object) ⇒ Triple
constructor
Creates a new triple with the specified
subject
,predicate
, andobject
. - #to_s ⇒ Object
Constructor Details
#initialize(subject, predicate, object) ⇒ Triple
Creates a new triple with the specified subject
, predicate
, and object
.
Raises:
- ArgumentError
-
if any of the parameters is nil.
- LiteralNodeSubjectError
-
if
subject
is a LiteralNode. - LiteralNodePredicateError
-
if
predicate
is a LiteralNode. - BlankNodePredicateError
-
if
predicate
is a BlankNode.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rdf/triple.rb', line 28 def initialize(subject, predicate, object) @subject = subject @predicate = predicate @object = object raise ArgumentError, 'subject must be a node' unless RDF::Node?(@subject) raise ArgumentError, 'predicate must be a node' unless RDF::Node?(@predicate) raise ArgumentError, 'object must be a node' unless RDF::Node?(@object) raise RDF::InvalidSubjectError, "#{@subject} must be a blank or uri node" unless RDF::BlankNode?(@subject) || RDF::UriNode?(@subject) raise RDF::InvalidPredicateError, "#{@predicate} must be a uri node" unless RDF::UriNode?(@predicate) end |
Instance Attribute Details
#object ⇒ Object (readonly)
the object of this triple
19 20 21 |
# File 'lib/rdf/triple.rb', line 19 def object @object end |
#predicate ⇒ Object (readonly)
the predicate of this triple
17 18 19 |
# File 'lib/rdf/triple.rb', line 17 def predicate @predicate end |
#subject ⇒ Object (readonly)
the subject of this triple
15 16 17 |
# File 'lib/rdf/triple.rb', line 15 def subject @subject end |
Class Method Details
Instance Method Details
#==(o) ⇒ Object Also known as: eql?
Returns true if o
is a Triple with the same subject
, object
, and predicate
.
42 43 44 45 46 47 48 |
# File 'lib/rdf/triple.rb', line 42 def ==(o) if RDF::Triple?(o) subject == o.subject && predicate == o.predicate && object == o.object end end |
#hash ⇒ Object
Returns a hash value for this Triple.
53 54 55 |
# File 'lib/rdf/triple.rb', line 53 def hash [-78640401, subject.hash, predicate.hash, object.hash].hash end |
#to_s ⇒ Object
57 58 59 |
# File 'lib/rdf/triple.rb', line 57 def to_s "#{subject} #{predicate} #{object}." end |