Parent

Namespace

Readorder::Filelist

An interator over the contents of a bunch of files or IO objects depending on the initializer.

Public Class Methods

new( sources = [] ) click to toggle source

(Not documented)

# File lib/readorder/filelist.rb, line 9
    def initialize( sources = [] )
      @sources = [ sources ].flatten
      @current_source = nil
      @sources.each do |s|
        case s
        when String
          raise Error, "#{s} does not exist" unless File.exist?( s )
          raise Error, "#{s} is not readable" unless File.readable?( s )
        else
          [ :gets, :close ].each do |meth|
            raise Error, "#{s.inspect} does not respond to '#{meth}'" unless s.respond_to? meth
          end
        end
      end
    end

Public Instance Methods

current_source() click to toggle source

(Not documented)

# File lib/readorder/filelist.rb, line 25
    def current_source
      if not @current_source then 
        cs = @sources.shift
        case cs
        when String
          @current_source = File.open( cs )
        else
          # nil or respond_to? :gets
          @current_source = cs
        end
      end
      return @current_source
    end
each_line() click to toggle source

Iterator yielding the line returned, stopping on no more lines

# File lib/readorder/filelist.rb, line 55
    def each_line
      while line = self.gets do
        yield line
      end
    end
gets() click to toggle source

return the next line from the sources, opening a new source if need be

# File lib/readorder/filelist.rb, line 41
    def gets
      loop do
        return nil unless self.current_source
        line = self.current_source.gets
        return line if line

        @current_source.close unless @current_source == $stdin
        @current_source = nil
      end
    end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.