Class: Reddy::Triple

Inherits:
Object
  • Object
show all
Defined in:
lib/reddy/triple.rb

Defined Under Namespace

Classes: InvalidObject, InvalidPredicate, InvalidSubject

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject, predicate, object) ⇒ Triple

Creates a new triple directly from the intended subject, predicate, and object.

Example

Triple.new(BNode.new, URIRef.new("http://xmlns.com/foaf/0.1/knows"), BNode.new) # => results in the creation of a new triple and returns it

Returns

Parameters:

Raises:

  • (Error)

    Checks parameter types and raises if they are incorrect.

Author:

  • Tom Morris



30
31
32
33
34
# File 'lib/reddy/triple.rb', line 30

def initialize (subject, predicate, object)
  @subject   = self.class.coerce_subject(subject)
  @predicate = self.class.coerce_predicate(predicate)
  @object    = self.class.coerce_object(object)
end

Instance Attribute Details

#objectObject

Returns the value of attribute object.



12
13
14
# File 'lib/reddy/triple.rb', line 12

def object
  @object
end

#predicateObject

Returns the value of attribute predicate.



12
13
14
# File 'lib/reddy/triple.rb', line 12

def predicate
  @predicate
end

#subjectObject

Returns the value of attribute subject.



12
13
14
# File 'lib/reddy/triple.rb', line 12

def subject
  @subject
end

Instance Method Details

#inspectObject



40
41
42
# File 'lib/reddy/triple.rb', line 40

def inspect
  [@subject, @predicate, @object].inspect
end

#is_type?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/reddy/triple.rb', line 44

def is_type?
  @predicate.to_s == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
end

#to_ntriplesObject



36
37
38
# File 'lib/reddy/triple.rb', line 36

def to_ntriples
  @subject.to_ntriples + " " + @predicate.to_ntriples + " " + @object.to_ntriples + " ."
end