Class: Amigo::Store

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

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.



15
16
17
# File 'lib/amigo/store.rb', line 15

def initialize
  @triples = Hamster.set
end

Instance Method Details

#add(subject, predicate, object) ⇒ Object



19
20
21
22
23
# File 'lib/amigo/store.rb', line 19

def add(subject, predicate, object)
  triple = Triple.new(subject, predicate, object)
  return self if @triples.include?(triple)
  transform { @triples = @triples.add(triple) }
end

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

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/amigo/store.rb', line 33

def eql?(other)
  return true if other.equal?(self)
  other.class.equal?(self.class) &&
    @triples.eql?(other.instance_variable_get(:@triples))
end

#execute(query) ⇒ Object



25
26
27
# File 'lib/amigo/store.rb', line 25

def execute(query)
  query.execute(@triples)
end

#hashObject



40
41
42
# File 'lib/amigo/store.rb', line 40

def hash
  @triples.hash
end

#to_ntriplesObject



29
30
31
# File 'lib/amigo/store.rb', line 29

def to_ntriples
  @triples.map(&:to_ntriple).join("\n")
end