StdlibDoc::GenDoc::LineCounter (Module)

In: StdlibDoc/Status/LineCounter.rb

Implements the method LineCounter.loc(path) which counts the lines of Ruby code in a file.

Methods

loc  

Public Class methods

Returns a hash with three values:

  • total lines (including blank)
  • lines of code (non-blank, non-comment)
  • lines of comments

The keys of the hash are :total, :code, and :comments

[Source]

# 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

[Validate]