Class: RdfaParser::Triple

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

Overview

Triple from Reddy, to aid it merger

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



22
23
24
25
26
# File 'lib/rdfa_parser/triple.rb', line 22

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.



4
5
6
# File 'lib/rdfa_parser/triple.rb', line 4

def object
  @object
end

#predicateObject

Returns the value of attribute predicate.



4
5
6
# File 'lib/rdfa_parser/triple.rb', line 4

def predicate
  @predicate
end

#subjectObject

Returns the value of attribute subject.



4
5
6
# File 'lib/rdfa_parser/triple.rb', line 4

def subject
  @subject
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


42
43
44
45
46
47
# File 'lib/rdfa_parser/triple.rb', line 42

def eql? (other)
  other.is_a?(self.class) &&
  other.subject == self.subject &&
  other.predicate == self.predicate &&
  other.object == self.object
end

#inspectObject



34
35
36
# File 'lib/rdfa_parser/triple.rb', line 34

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

#is_type?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/rdfa_parser/triple.rb', line 38

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

#to_ntriplesObject



28
29
30
# File 'lib/rdfa_parser/triple.rb', line 28

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

#to_sObject



32
# File 'lib/rdfa_parser/triple.rb', line 32

def to_s; self.to_ntriples; end