Module: RDF::Writable
- Extended by:
- Util::Aliasing::LateBound
- Included in:
- Mutable, Writer
- Defined in:
- lib/rdf/mixin/writable.rb
Instance Method Summary (collapse)
-
- (RDF::Writable) <<(data)
Inserts RDF data into
self. -
- (RDF::Writable) insert(*statements)
(also: #insert!)
Inserts RDF statements into
self. -
- insert_graph(graph)
protected
Inserts the given RDF graph into the underlying storage or output stream.
-
- insert_reader(reader)
protected
Inserts statements from the given RDF reader into the underlying storage or output stream.
-
- insert_statement(statement)
protected
Abstract
Inserts an RDF statement into the underlying storage or output stream.
-
- insert_statements(statements)
protected
Inserts the given RDF statements into the underlying storage or output stream.
-
- (Boolean) writable?
Returns
trueifselfis writable.
Methods included from Util::Aliasing::LateBound
Instance Method Details
- (RDF::Writable) <<(data)
Inserts RDF data into self.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rdf/mixin/writable.rb', line 20 def <<(data) case data when RDF::Reader insert_reader(data) when RDF::Graph insert_graph(data) when RDF::Enumerable insert_statements(data) when RDF::Statement insert_statement(data) else case when data.respond_to?(:to_rdf) && !data.equal?(rdf = data.to_rdf) self << rdf else insert_statement(Statement.from(data)) end end return self end |
- (RDF::Writable) insert(*statements) Also known as: insert!
Inserts RDF statements into self.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rdf/mixin/writable.rb', line 46 def insert(*statements) statements.map! do |value| case when value.respond_to?(:each_statement) insert_statements(value) nil when (statement = Statement.from(value)).valid? statement else raise ArgumentError.new("not a valid statement: #{value.inspect}") end end statements.compact! insert_statements(statements) unless statements.empty? return self end |
- insert_graph(graph) (protected)
This method returns an undefined value.
Inserts the given RDF graph into the underlying storage or output stream.
Defaults to passing the graph to the #insert_statements method.
Subclasses of Repository may wish to override this method in case their underlying storage architecture is graph-centric rather than statement-oriented.
Subclasses of RDF::Writer may wish to override this method if the output format they implement supports named graphs, in which case implementing this method may help in producing prettier and more concise output.
102 103 104 |
# File 'lib/rdf/mixin/writable.rb', line 102 def insert_graph(graph) insert_statements(graph) end |
- insert_reader(reader) (protected)
This method returns an undefined value.
Inserts statements from the given RDF reader into the underlying storage or output stream.
Defaults to passing the reader to the #insert_statements method.
Subclasses of Repository may wish to override this method in case their underlying storage can efficiently import RDF data directly in particular serialization formats, thus avoiding the intermediate parsing overhead.
81 82 83 |
# File 'lib/rdf/mixin/writable.rb', line 81 def insert_reader(reader) insert_statements(reader) end |
- insert_statement(statement) (protected)
This method returns an undefined value.
Inserts an RDF statement into the underlying storage or output stream.
Subclasses of Repository must implement this method, except if they are immutable.
Subclasses of RDF::Writer must implement this method.
140 141 142 |
# File 'lib/rdf/mixin/writable.rb', line 140 def insert_statement(statement) raise NotImplementedError.new("#{self.class}#insert_statement") end |
- insert_statements(statements) (protected)
This method returns an undefined value.
Inserts the given RDF statements into the underlying storage or output stream.
Defaults to invoking #insert_statement for each given statement.
Subclasses of Repository may wish to override this method if they are capable of more efficiently inserting multiple statements at once.
Subclasses of RDF::Writer don't generally need to implement this method.
122 123 124 125 126 127 |
# File 'lib/rdf/mixin/writable.rb', line 122 def insert_statements(statements) each = statements.respond_to?(:each_statement) ? :each_statement : :each statements.__send__(each) do |statement| insert_statement(statement) end end |
- (Boolean) writable?
Returns true if self is writable.
11 12 13 |
# File 'lib/rdf/mixin/writable.rb', line 11 def writable? true end |