| In: |
StdlibDoc/Status/LineCounter.rb
|
Implements the method LineCounter.loc(path) which counts the lines of Ruby code in a file.
Returns a hash with three values:
The keys of the hash are :total, :code, and :comments
# File StdlibDoc/Status/LineCounter.rb, line 22 def LineCounter.loc(path) total = 0 code = 0 comments = 0 rd_comment = false File.foreach(path) do |line| total += 1 if rd_comment if line =~ /^\s*=end/ rd_comment = false end comments += 1 else case line when /^\s*=begin/ rd_comment = true comments += 1 when /^\s*#/ comments += 1 when /^\s*$/ # blank line else code += 1 end end end return { :total => total, :code => code, :comments => comments } end