/**
 * Copyright 2005-2007 Yu Zhang
 * Distributed under the GNU General Public License 2.0
 */

package com.xruby.runtime.value;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.xruby.runtime.lang.RubyBasic;
import com.xruby.runtime.lang.RubyRuntime;

public class RubyDir extends RubyBasic{
    private File dir_;
    private boolean isOpen = true;
    private int curPos;
    private List<String> list = new ArrayList<String>();
    
    public RubyDir(String path){
        super(RubyRuntime.DirClass);
        dir_ = new File(path);
        
        list.add(".");
        list.add("..");
        String[] contents = dir_.list();
        if(contents != null){
            for(int i=0;i<contents.length;i++){
                list.add(contents[i]);
            }
        }
        curPos = 0;
    }
    
    public boolean isDirectory(){
        return dir_.isDirectory();
    }
    
    public void close(){
        isOpen = false;
    }
    
    public boolean isOpen(){
        return isOpen;
    }
    
    public String read(){
        if(curPos >= list.size())
            return null;
        
        String tmp = list.get(curPos);
        curPos++;
        return tmp;
    }
}

@@ -284,22 +284,106 @@
 ang.Ruby
-Runtim
+Block;%0D%0Aimport com.xruby.runtime.lang.RubyRuntime;%0D%0Aimport com.xruby.runtime.lang.RubyValu
 e;%0D%0A%0D%0Apu
@@ -1355,11 +1355,478 @@
 %0A    %7D%0D%0A
+    %0D%0A    public void setPos(int pos)%7B%0D%0A        curPos = pos;%0D%0A    %7D%0D%0A    %0D%0A    public int getPos()%7B%0D%0A        return curPos;%0D%0A    %7D%0D%0A    %0D%0A    public RubyValue each(RubyValue receiver,RubyBlock block)%7B%0D%0A        for (String item : list) %7B%0D%0A            RubyValue v = block.invoke(receiver, new RubyArray(ObjectFactory.createString(item)));%0D%0A            if (block.breakedOrReturned()) %7B%0D%0A                return v;%0D%0A            %7D%0D%0A        %7D%0D%0A        return this;%0D%0A    %7D%0D%0A
 %7D%0D%0A

add helper method