Class: RDF::SPARQL::Writer
- Inherits:
-
Writer
- Object
- Writer
- RDF::SPARQL::Writer
- Includes:
- Common
- Defined in:
- lib/lib/writer.rb
Instance Method Summary collapse
-
#initialize(output = $stdout, options = {}) {|writer| ... } ⇒ Writer
constructor
A new instance of Writer.
-
#new_target(name_or_uri = nil) ⇒ Object
[-].
-
#write_query ⇒ Object
[-].
-
#write_triple(subject, predicate, object) ⇒ void
Stores the SPARQL representation of a triple.
- #write_triples(triples) ⇒ Object
Methods included from Common
#distinct?, #each_statement, #each_target, #each_triple, #each_variable, #reduced?, #statements, #targets, #triples, #type, #variables
Constructor Details
#initialize(output = $stdout, options = {}) {|writer| ... } ⇒ Writer
Returns a new instance of Writer.
12 13 14 15 16 17 18 19 20 |
# File 'lib/lib/writer.rb', line 12 def initialize(output = $stdout, = {}, &block) @output, @options = output, @graph = RDF::Graph.new @targets = [] if block_given? block.call(self) write_query end end |
Instance Method Details
#new_target(name_or_uri = nil) ⇒ Object
- -
44 45 46 47 48 49 50 51 |
# File 'lib/lib/writer.rb', line 44 def new_target(name_or_uri = nil) @targets << case name_or_uri when String then RDF::Query::Variable.new(name_or_uri) when RDF::URI then name_or_uri else RDF::Query::Variable.new('v%s' % rand(10000)) end @targets.last end |
#write_query ⇒ Object
- -
56 57 58 59 60 |
# File 'lib/lib/writer.rb', line 56 def write_query puts format_prologue puts format_where puts write_epilogue end |
#write_triple(subject, predicate, object) ⇒ void
This method returns an undefined value.
Stores the SPARQL representation of a triple.
31 32 33 |
# File 'lib/lib/writer.rb', line 31 def write_triple(subject, predicate, object) @graph << RDF::Query::Pattern.new(subject, predicate, object) end |
#write_triples(triples) ⇒ Object
37 38 39 |
# File 'lib/lib/writer.rb', line 37 def write_triples(triples) triples.each { |triple| write_triple(*triple) } end |