class KXI::Collections::HashCollection::HashEnumerator

Enumerates hash as key-value pairs represented by the {KXI::Collections::HashCollection::HashEnumerator::KeyValuePair} class

Public Class Methods

new(hash) click to toggle source

Instantiates the {KXI::Collections::HashCollection::HashEnumerator} class @param hash [Hash] Hash for enumeration

# File lib/kxi/collections/hash_collection.rb, line 45
def initialize(hash)
        @hash = hash
        @keys = hash.keys
        @current = 0
end

Public Instance Methods

current() click to toggle source

Returns current item @return [Object] Current item @raise [KXI::Exceptions::AbstractException] When method is not implemented in superclass

# File lib/kxi/collections/hash_collection.rb, line 69
def current
        k = @keys[@current]
        KeyValuePair.new(k, @hash[k])
end
next() click to toggle source

Advances enumerator to next item @return [Bool] True if item is available; false otherwise @raise [KXI::Exceptions::AbstractException] When method is not implemented in superclass

# File lib/kxi/collections/hash_collection.rb, line 61
def next
        @current += 1
        return @keys.length > @current
end
rewind() click to toggle source

Selects first item in collection @return [Bool] True if collection contains elements; otherwise false

# File lib/kxi/collections/hash_collection.rb, line 53
def rewind
        @current = 0
        return @keys.length > 0
end