Class: RdfContext::ListStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- RdfContext::ListStore
- Defined in:
- lib/rdf_context/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, #uri_binding
Instance Method Summary collapse
-
#add(triple, context, quoted = false) ⇒ Triple
Add triple to store.
-
#contains?(triple, context = nil) ⇒ Boolean
Check to see if this store contains the specified triple.
-
#destroy(configuration = {}) ⇒ Object
Destroy the store, as it can contain only one context.
-
#initialize(identifier = nil, configuration = {}) ⇒ ListStore
constructor
A new instance of ListStore.
-
#inspect ⇒ ListStore
Create a new ListStore Store, should be subclassed @param configuration Specific to type of storage.
-
#remove(triple, context, quoted = false)
Remove a triple from the store.
-
#triples(triple, context = nil) {|triple, context| ... } ⇒ Array<Triplle>
Triples from graph, optionally matching subject, predicate, or object.
Methods inherited from AbstractStore
#bind, #bnodes, #close, #commit, #context_aware?, #contexts, #formula_aware?, #item, #namespace, #objects, #open, #predicates, #prefix, #rollback, #size, #subjects, #transaction_aware?
Constructor Details
#initialize(identifier = nil, configuration = {}) ⇒ ListStore
Returns a new instance of ListStore.
6 7 8 9 |
# File 'lib/rdf_context/store/list_store.rb', line 6 def initialize(identifier = nil, configuration = {}) super @triples = [] end |
Instance Method Details
#add(triple, context, quoted = false) ⇒ Triple
Add triple to store
29 30 31 |
# File 'lib/rdf_context/store/list_store.rb', line 29 def add(triple, context, quoted = false) @triples << triple unless contains?(triple, context) end |
#contains?(triple, context = nil) ⇒ Boolean
Check to see if this store contains the specified triple
49 50 51 |
# File 'lib/rdf_context/store/list_store.rb', line 49 def contains?(triple, context = nil) @triples.any? {|t| t == triple} end |
#destroy(configuration = {}) ⇒ Object
Destroy the store, as it can contain only one context
20 21 22 |
# File 'lib/rdf_context/store/list_store.rb', line 20 def destroy(configuration = {}) @triples = [] end |
#inspect ⇒ ListStore
Create a new ListStore Store, should be subclassed @param configuration Specific to type of storage
15 16 17 |
# File 'lib/rdf_context/store/list_store.rb', line 15 def inspect "ListStore[id=#{identifier}, size=#{@triples.length}]" end |
#remove(triple, context, quoted = false)
This method returns an undefined value.
Remove a triple from the store
If the triple does not provide a context attribute, removes the triple from all contexts.
41 42 43 |
# File 'lib/rdf_context/store/list_store.rb', line 41 def remove(triple, context, quoted = false) @triples.delete(triple) end |
#triples(triple, context = nil) {|triple, context| ... } ⇒ Array<Triplle>
Triples from graph, optionally matching subject, predicate, or object. Delegated from Graph. See Graph#triples for details.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rdf_context/store/list_store.rb', line 62 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 if block_given? yield t end t end.compact elsif block_given? @triples.each {|triple| yield triple} else @triples end end |