Module: RDF::Util::Coercions
Instance Method Summary collapse
-
#coerce_statements(statements, query: false, constant: false) {|RDF::Statement, RDF::Enumerable| ... } ⇒ Object
protected
Coerce an array of arguments into Statement, or Enumerable and then yield to a block.
Instance Method Details
#coerce_statements(statements, query: false, constant: false) {|RDF::Statement, RDF::Enumerable| ... } ⇒ Object (protected)
Coerce an array of arguments into Statement, or
Enumerable and then yield to a block. Note that this
code was amalgamated from that which was sandwiched around
both Writable#insert_statements and
Mutable#delete_statements. The parameters query
and
constant
are therefore present to handle the conditions
where the statements contain wildcards and what to do about
them.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rdf/util/coercions.rb', line 32 def coerce_statements(statements, query: false, constant: false, &block) raise ArgumentError, 'expecting a block' unless block_given? statements = statements.map do |value| case when value.respond_to?(:each_statement) block.call(value) nil when (statement = Statement.from(value)) && (!constant || statement.constant?) statement when query # XXX note that this only makes sense when the module is include()d block.call(self.query(value)) nil else raise ArgumentError, "Not a valid statement: #{value.inspect}" end end.compact block.call(statements) unless statements.empty? # eh might as well return these statements end |