Sha256: 7af302b37d4222d6da31ecbaf819e2909105b2e192a799fcdd9e2e2d216353c1

Contents?: true

Size: 662 Bytes

Versions: 2

Compression:

Stored size: 662 Bytes

Contents

class SourceFile < File

  # start read the file object on each line
  # optionable an integer value to start read line at
  # compatible with mac (i am linux user, so not tested)
  def each_line_from(start_at=1,&block)
    unless [Integer,Fixnum,Bignum].include?(start_at.class)
      raise ArgumentError, "invalid line index"
    end
    begin

      line_num= 1
      text= self.read
      text.gsub!(/\r\n?/, "\n")
      text.gsub!(';',"\n")
      text.gsub!(/\bdo\b/,'{')
      text.gsub!(/\bend\b/,'}')
      text.each_line do |*line|
        if line_num >= start_at
          block.call *line
        end
        line_num += 1
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sourcerer-0.5.2 lib/sourcerer/file.rb
sourcerer-0.5.1 lib/sourcerer/file.rb