Redland RDF Application Framework - Ruby RDoc - Class: Redland::NodeIterator

Go to Redland Home - Language Bindings Home - Ruby API Home

Class | Redland::NodeIterator
In: | rdf/redland/stream.rb
Parent: | Object

The iterator provides a generic way to receive a sequence of values (order may or may not be import) from objects, usually generated on demand.

### Methods

create_finalizer current end? new next

### Included Modules

Util

### Public Class methods

create_finalizer(iterator)

You shouldn‘t use this. Used internally for cleanup.

[Source]

    # File rdf/redland/stream.rb, line 114
        def NodeIterator.create_finalizer(iterator)
          proc {|id| "Finalizer on #{id}"
            #puts "closing iterator"
            Redland::librdf_free_iterator(iterator)
          }
        end

new(object,model=nil,creator2=nil,creator3=nil)

[Source]

    # File rdf/redland/stream.rb, line 82
        def initialize(object,model=nil,creator2=nil,creator3=nil)
          @iterator = object
          @model = model
          @creator2 = creator2
          @creator3 = creator3

          # Test if the iterator has finished
          def end?()
            return (Redland.librdf_iterator_end(@iterator) != 0)
          end

          # Get the current object from the iterator
          def current
            my_node = Redland.librdf_iterator_get_object(@iterator)
            if my_node == "NULL" or my_node == nil
              return nil
            elsif is_literal?(my_node)
              return Literal.from_node(my_node)
            else
              return Resource.new(my_node,@model)
            end
          end

          # Move to the next iterator element
          def next()
            my_node=Redland.librdf_iterator_next(@iterator)
          end

          ObjectSpace.define_finalizer(self,NodeIterator.create_finalizer(@iterator))
        end

### Public Instance methods

current()

Get the current object from the iterator

[Source]

    # File rdf/redland/stream.rb, line 94
          def current
            my_node = Redland.librdf_iterator_get_object(@iterator)
            if my_node == "NULL" or my_node == nil
              return nil
            elsif is_literal?(my_node)
              return Literal.from_node(my_node)
            else
              return Resource.new(my_node,@model)
            end
          end

end?()

Test if the iterator has finished

[Source]

    # File rdf/redland/stream.rb, line 89
          def end?()
            return (Redland.librdf_iterator_end(@iterator) != 0)
          end

next()

Move to the next iterator element

[Source]

    # File rdf/redland/stream.rb, line 106
          def next()
            my_node=Redland.librdf_iterator_next(@iterator)
          end

Go to Redland Home - Language Bindings Home - Ruby API Home

(C) Copyright 2004-2011 Dave Beckett, (C) Copyright 2004-2005 University of Bristol