项目文件行数计算
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
## ## this is design for calculate the totals line of code in your project ## version 1 @october 8th,2008 ## module Enumerable # function to get total lines for file def total_lines lines = 0 each_with_index {|content,lines|} return lines+1 end end class CheckLines require 'find' @check_type = %w{txt rb erb yml html css xml} def initialize(directory) @total_lines = 0 if File.directory?(directory) @directory = directory @contents = {} self.go else puts "#{directory} is not a directory! check it out!" and return end end def go if @directory Find.find @directory do |path| pathlite = path.gsub(@directory,'') if File.file? path File.open path do |f| tmp_line = f.total_lines @contents.store(pathlite,tmp_line) @total_lines += tmp_line end end end puts @total_lines end end def details @contents.each do |key,value| puts "#{key} file has lines of #{value}" end end end |
上课前临时写的,回来加强。
Posted by xhan At October 08, 2008 09:15
请登录以发表评论。