XCODE 脚本:项目行数统计

统计项目行数,从某方面也可以陶醉下自己项目规模。
暴力推荐无聊发呆时候使用。

这个从自己一个最早期Rails项目中剥离出来,虽然简单,不过勉强能用了。
使用方法:打开脚本编辑器。添加新脚本。拷贝代码,OutPut 选择 display in alert

That's all , Enjoy!

#!/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?


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值