Class: Amigo::Triple

Inherits:
Object show all
Includes:
Hamster::Immutable
Defined in:
lib/amigo/triple.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject, predicate, object) ⇒ Triple

Returns a new instance of Triple.



12
13
14
15
16
# File 'lib/amigo/triple.rb', line 12

def initialize(subject, predicate, object)
  @subject = subject
  @predicate = predicate
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



10
11
12
# File 'lib/amigo/triple.rb', line 10

def object
  @object
end

#predicateObject (readonly)

Returns the value of attribute predicate.



10
11
12
# File 'lib/amigo/triple.rb', line 10

def predicate
  @predicate
end

#subjectObject (readonly)

Returns the value of attribute subject.



10
11
12
# File 'lib/amigo/triple.rb', line 10

def subject
  @subject
end

Instance Method Details

#<=>(other) ⇒ Object



39
40
41
# File 'lib/amigo/triple.rb', line 39

def <=>(other)
  [subject, predicate, object] <=> [other.subject, other.predicate, other.object]
end

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

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/amigo/triple.rb', line 26

def eql?(other)
  return true if other.equal?(self)
  return other.class.equal?(self.class) &&
    other.subject == self.subject &&
    other.predicate == self.predicate &&
    other.object == self.object
end

#hashObject



35
36
37
# File 'lib/amigo/triple.rb', line 35

def hash
  subject.hash ^ predicate.hash ^ object.hash
end

#inspectObject



22
23
24
# File 'lib/amigo/triple.rb', line 22

def inspect
  to_ntriple
end

#to_ntripleObject



18
19
20
# File 'lib/amigo/triple.rb', line 18

def to_ntriple
  "#{[@subject, @predicate, @object].map(&:to_ntriple).join(" ")} ."
end