Sha256: f1558e2bd09155aafe36f713254bffa1daf815253e5c9a78d1e405fa1e2029b4

Contents?: true

Size: 1.16 KB

Versions: 30

Compression:

Stored size: 1.16 KB

Contents

def extract_path(argv)
  if argv[1].nil?
    if argv[0] =~ /-a/
      return "/**/*.rb"
    elsif argv[0]
      if argv[0] =~ /\.rb$/
        return argv[0]
      end
      return argv[0] + "/**/*.rb"
    else
      return "/**/*.rb"
    end
  elsif argv[1] =~ /\.rb$/
    return argv[1]
  else
    return argv[1] + "/**/*.rb"
  end
end

def all?
  ARGV.join =~ /-a/
end

def comment?(line)
  line =~ /^\s*#/
end

def blank?(line)
  line =~ /^\s*$/
end

def puke(header, locs, comments, blanks)
  puts header + ":"
  puts "#{locs} loc"
  puts "#{comments} lines of comments"
  puts "#{blanks} blank lines"
end

dir = File.dirname(__FILE__)
full_path = File.join(dir,extract_path(ARGV))
gloc = gcmts = gblanks = 0
Dir[File.expand_path("#{full_path}")].uniq.each do |file|
  if file =~ /.*\.rb$/ 
    
    loc = cmts = blanks = 0

    File.open(file, "r") do |f|
      while f.gets
        if comment?($_)
          cmts += 1
        elsif blank?($_)
          blanks += 1
        else
          loc += 1
        end
      end
    end
    gcmts   += cmts
    gloc    += loc
    gblanks += blanks 
    puke(file, loc, cmts, blanks) if all?
  end
end
puke("Total", gloc, gcmts, gblanks)

Version data entries

30 entries across 30 versions & 5 rubygems

Version Path
auser-poolparty-1.3.0 vendor/gems/context/countloc.rb
auser-poolparty-1.3.1 vendor/gems/context/countloc.rb
auser-poolparty-1.3.10 vendor/gems/context/countloc.rb
auser-poolparty-1.3.11 vendor/gems/context/countloc.rb
auser-poolparty-1.3.12 vendor/gems/context/countloc.rb
auser-poolparty-1.3.13 vendor/gems/context/countloc.rb
auser-poolparty-1.3.14 vendor/gems/context/countloc.rb
auser-poolparty-1.3.15 vendor/gems/context/countloc.rb
auser-poolparty-1.3.16 vendor/gems/context/countloc.rb
auser-poolparty-1.3.17 vendor/gems/context/countloc.rb
auser-poolparty-1.3.2 vendor/gems/context/countloc.rb
auser-poolparty-1.3.3 vendor/gems/context/countloc.rb
auser-poolparty-1.3.4 vendor/gems/context/countloc.rb
auser-poolparty-1.3.5 vendor/gems/context/countloc.rb
auser-poolparty-1.3.6 vendor/gems/context/countloc.rb
auser-poolparty-1.3.7 vendor/gems/context/countloc.rb
auser-poolparty-1.3.8 vendor/gems/context/countloc.rb
fairchild-poolparty-1.3.17 vendor/gems/context/countloc.rb
fairchild-poolparty-1.3.5 vendor/gems/context/countloc.rb
tu-context-0.5.7 countloc.rb