Module: RDF::RDFObjects::Graph
- Included in:
- Graph
- Defined in:
- lib/rdf/rdfobjects/graph.rb
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #[](id) ⇒ Object
- #create(*args, &block) ⇒ Object
- #insert_statement(statement) ⇒ Object
- #to_ntriples ⇒ Object
Instance Method Details
#<<(data) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rdf/rdfobjects/graph.rb', line 25 def <<(data) case data when RDF::RDFObjects::Resource data.statements.each do |stmt| self.insert(stmt) end else super(data) end end |
#[](id) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/rdf/rdfobjects/graph.rb', line 9 def [](id) id = RDF::Resource.new(id) unless id.is_a?(Resource) r = self.first_subject(:subject=>id) r = self.first_object(:object=>id) unless r r.graph = self if r r end |
#create(*args, &block) ⇒ Object
3 4 5 6 7 |
# File 'lib/rdf/rdfobjects/graph.rb', line 3 def create(*args, &block) r = RDF::Resource.new(args.shift, *args, &block) r.graph = self r end |
#insert_statement(statement) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/rdf/rdfobjects/graph.rb', line 36 def insert_statement(statement) statement = statement.dup statement.context = context statement.each_triple.each do |s,p,o| puts s.to_s s.graph = self if s.is_a?(RDF::Resource) end @data.insert(statement) end |
#to_ntriples ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/rdf/rdfobjects/graph.rb', line 17 def to_ntriples RDF::Writer.for(:ntriples).buffer do |writer| self.each_statement do |statement| writer << statement end end end |