Class: SourceFile

Inherits:
File
  • Object
show all
Defined in:
lib/sourcerer/file.rb

Instance Method Summary collapse

Instance Method Details

#each_line_from(start_at = 1, &block) ⇒ Object

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)



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sourcerer/file.rb', line 6

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