Kiss A simpler, smarter web application framework for Ruby

Kiss::Iterator Subclass of Object

Description

Enables `loop’ features for certain template loops (while, for...in). Similar to features of Perl’s Template::Iterator by Andy Wardley.

Attributes

collectionread-only

Not documented

indexread-only

Not documented

Public Class Methods

new(collection = nil) source

Creates a new loop iterator.

    # File lib/kiss/iterator.rb, line 8
    def initialize(collection = nil)
      @collection = collection
      @index = -1
    end
    

Public Instance Methods

count() source

Return current iteration number, indexed from one instead of zero.

    # File lib/kiss/iterator.rb, line 14
    def count
      @index + 1
    end
    
first() source

Returns true if this is loop’s first iteration.

    # File lib/kiss/iterator.rb, line 19
    def first
      @index == 0
    end
    
increment() source

Used by template erubis pre-processing voodoo to advance the iterator index. Not intended for any other use.

    # File lib/kiss/iterator.rb, line 52
    def increment
      @index = @index + 1
    end
    
last() source

Returns true if this is the last iteration of a loop over a collection.

    # File lib/kiss/iterator.rb, line 25
    def last
      count == size
    end
    
max() source

Returns index of loop’s last iteration.

    # File lib/kiss/iterator.rb, line 40
    def max
      @collection ? @collection.size-1 : nil
    end
    
next() source

Return next item in loop-iterated collection.

    # File lib/kiss/iterator.rb, line 35
    def next
      @collection ? @collection[index+1] : nil
    end
    
prev() source

Return previous item in loop-iterated collection.

    # File lib/kiss/iterator.rb, line 30
    def prev
      @collection ? @collection[index-1] : nil
    end
    
size() source

Returns number of iterations in loop over a collection (size of the iterated collection).

    # File lib/kiss/iterator.rb, line 46
    def size
      @collection ? @collection.size : nil
    end
    

Disabled; run with $DEBUG to generate this.