Module: RDF::Writable
- Extended by:
- Util::Aliasing::LateBound
- Includes:
- Util::Coercions
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/mixin/writable.rb
Overview
Classes that include this module must implement the methods
#insert_statement
.
Instance Method Summary collapse
-
#<<(data) ⇒ self
Inserts RDF data into
self
. -
#insert(*statements) ⇒ Object
(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.
-
#writable? ⇒ Boolean
Returns
true
ifself
is writable.
Methods included from Util::Aliasing::LateBound
Methods included from Util::Coercions
Instance Method Details
#<<(data) ⇒ self
Inserts RDF data into self
.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/mixin/writable.rb', line 26 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 |
#insert(*statements) ⇒ self #insert(statements) ⇒ self Also known as: insert!
using splat argument syntax with excessive arguments provided
Inserts RDF statements into self
.
significantly affects performance. Use Enumerator form for large numbers of statements.
63 64 65 66 67 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/mixin/writable.rb', line 63 def insert(*statements) coerce_statements(statements) { |value| insert_statements value } 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.
106 107 108 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/mixin/writable.rb', line 106 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.
85 86 87 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/mixin/writable.rb', line 85 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.
153 154 155 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/mixin/writable.rb', line 153 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.
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/mixin/writable.rb', line 127 def insert_statements(statements) each = statements.respond_to?(:each_statement) ? :each_statement : :each statements.__send__(each) do |statement| # FIXME: quoted triples are now deprecated if statement. && respond_to?(:supports?) && !(supports?(:quoted_triples) || supports?(:rdf_full)) raise ArgumentError, "Writable does not support quoted triples" end if statement.object && statement.object.literal? && statement.object.direction? && respond_to?(:supports?) && !supports?(:base_direction) raise ArgumentError, "Writable does not support directional languaged-tagged strings" end insert_statement(statement) end end |
#writable? ⇒ Boolean
Returns true
if self
is writable.
17 18 19 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/mixin/writable.rb', line 17 def writable? !frozen? end |