module Redlander class Stream attr_reader :rdf_stream def initialize(source) @rdf_stream = case source when Statement Redland.librdf_model_find_statements(source.model.rdf_model, source.rdf_statement) when Model Redland.librdf_model_as_stream(source.rdf_model) else # TODO raise NotImplementedError.new end raise RedlandError.new("Failed to create a new stream") if @rdf_stream.null? ObjectSpace.define_finalizer(self, proc { Redland.librdf_free_stream(@rdf_stream) }) end # End-of-stream? def eos? Redland.librdf_stream_end(@rdf_stream) != 0 end def succ Redland.librdf_stream_next(@rdf_stream).zero? end def current Statement.new(self) end # Return all the remaining statements in the stream # from the current position. def tail [].tap do |all| while !eos? all << current succ end end end end end