帖子
相册
日志
群组
热榜
分享
记录
银行
勋章中心
道具中心
基本信息
到访IP统计
管理团队
管理操作
在线会员
会员排行
版块排行
帖子排行
标签排行
#!/usr/bin/env ruby # description: Count code lines in project # Copyright by [email]xhan87@gmail.com[/email] # Sep 15 , 2009 ## ## this is designed to calculate the total lines of codes in your project ## version 2 @May 24, 2009 ## \- add file filter ,count specific file types add ## version 1 @october 8th,2008 module Enumerable # function to get total lines from a file def total_lines lines = 0 each_with_index {|content,lines|} return lines+1 end end class CheckLines require 'find' CheckType = %w{m h c cpp mm}.freeze def initialize(directory) @total_lines = 0 if File.directory?(directory) @directory = directory @contents = {} @content_type ={} CheckType.each {|ext| @content_type[ext.to_sym]=0} 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) && is_check_file(path) File.open path do |f| tmp_line = f.total_lines @contents.store(pathlite,tmp_line) @content_type[(path.sub(/.*\./,'').to_sym)] += tmp_line @total_lines += tmp_line end end end puts "Total Code Lines:#{@total_lines}" puts "Total Files #{@contents.keys.size}" @content_type.each_pair {|key,value| puts "#{key} : #{value}"} end end def is_check_file file_name CheckType.any? do |ext| !file_name.scan(/\.#{ext}$/).empty? end end def details @contents.each do |key,value| puts "#{key} file has lines of #{value}" end end end # s=CheckLines.new("/Users/xhan/Codes/plutocms") project_path = `%%%{PBXUtilityScriptsPath}%%%/AskUserForFolderDialog "Select A Project Home Folder"` #puts project_path CheckLines.new(project_path[0..-2]) unless project_path.empty?
引用 引用第7楼xhan于2009-10-02 10:36 PM发表的 :``555555 ~~~被鄙视了。
引用 引用楼主xhan于2009-09-15 23:57发表的 XCODE 脚本:项目行数统计 :统计项目行数,从某方面也可以陶醉下自己项目规模。暴力推荐无聊发呆时候使用。这个从自己一个最早期Rails项目中剥离出来,虽然简单,不过勉强能用了。使用方法:打开脚本编辑器。添加新脚本。拷贝代码,OutPut 选择 display in alert.......