Class: Reddy::ListStore

Inherits:
AbstractStore show all
Defined in:
lib/reddy/store/list_store.rb

Overview

List storage, most efficient, but slow storage model. Works well for basic parse and serialize.

Instance Attribute Summary

Attributes inherited from AbstractStore

#identifier, #nsbinding

Instance Method Summary collapse

Methods inherited from AbstractStore

#bind, #bnodes, context_aware?, formula_aware?, #item, #namespace, #objects, #predicates, #prefix, #size, #subjects

Constructor Details

#initialize(identifier = nil, configuration = {}) ⇒ ListStore

Returns a new instance of ListStore.



4
5
6
7
# File 'lib/reddy/store/list_store.rb', line 4

def initialize(identifier = nil, configuration = {})
  super
  @triples = []
end

Instance Method Details

#add(triple, context, quoted = false) ⇒ Object

Adds an extant triple to a graph.

context and quoted are ignored



17
18
19
# File 'lib/reddy/store/list_store.rb', line 17

def add(triple, context, quoted = false)
  @triples << triple unless contains?(triple, context)
end

#contains?(triple, context = nil) ⇒ Boolean

Check to see if this graph contains the specified triple

Returns:

  • (Boolean)


34
35
36
# File 'lib/reddy/store/list_store.rb', line 34

def contains?(triple, context = nil)
  !@triples.find_index(triple).nil?
end

#inspectObject



9
10
11
# File 'lib/reddy/store/list_store.rb', line 9

def inspect
  "ListStore[id=#{identifier}, size=#{@triples.length}]"
end

#remove(triple, context, quoted = false) ⇒ Object

Remove a triple from the graph

If the triple does not provide a context attribute, removes the triple from all contexts.



25
26
27
28
29
30
31
# File 'lib/reddy/store/list_store.rb', line 25

def remove(triple, context, quoted = false)
  if triple
    @triples.delete(triple)
  else
    @triples = []
  end
end

#triples(triple, context = nil) ⇒ Object

Triples from graph, optionally matching subject, predicate, or object. Delegated from Graph. See Graph#triples for details.

Author:

  • Gregg Kellogg



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/reddy/store/list_store.rb', line 42

def triples(triple, context = nil)
  subject = triple.subject
  predicate = triple.predicate
  object = triple.object
  
  if subject || predicate || object
    @triples.select do |t|
      next unless t == triple # Includes matching
        
      yield t if block_given?
      t
    end.compact
  elsif block_given?
    @triples.each {|triple| yield triple}
  else
    @triples
  end
end