Class: BBItools::CodeCouner
- Inherits:
-
Object
- Object
- BBItools::CodeCouner
- Defined in:
- lib/cocoapods-bb-PodAssistant/tools/count_code_line.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#line_number ⇒ Object
Returns the value of attribute line_number.
Class Method Summary collapse
Instance Method Summary collapse
-
#calculate_line_number ⇒ Object
统计行数.
-
#initialize(path) ⇒ CodeCouner
constructor
A new instance of CodeCouner.
Constructor Details
#initialize(path) ⇒ CodeCouner
Returns a new instance of CodeCouner.
9 10 11 12 |
# File 'lib/cocoapods-bb-PodAssistant/tools/count_code_line.rb', line 9 def initialize(path) @file_path = path @line_number = 0 end |
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path.
8 9 10 |
# File 'lib/cocoapods-bb-PodAssistant/tools/count_code_line.rb', line 8 def file_path @file_path end |
#line_number ⇒ Object
Returns the value of attribute line_number.
8 9 10 |
# File 'lib/cocoapods-bb-PodAssistant/tools/count_code_line.rb', line 8 def line_number @line_number end |
Class Method Details
.count_line(args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cocoapods-bb-PodAssistant/tools/count_code_line.rb', line 44 def self.count_line(args) file = args[0] if file.nil? puts "\033[31m参数异常,请传入一个参数(项目目录/要统计的文件目录/要统计的文件)\033[0m" return end counter = CodeCouner.new(file) counter.calculate_line_number puts "\033[32m统计#{counter.file_path}结束,共#{counter.line_number}行\033[0m" end |
Instance Method Details
#calculate_line_number ⇒ Object
统计行数
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 |
# File 'lib/cocoapods-bb-PodAssistant/tools/count_code_line.rb', line 14 def calculate_line_number puts "\033[33m正在统计#{@file_path} 代码行数,请稍后...\033[0m" if File.file?(@file_path) File.read(@file_path).each_line do |line| if line.match(/^\/\/|^$/) == nil #去掉单行注释和空行 @line_number = @line_number + 1 end end return end if File::directory?(@file_path) Find.find(@file_path) do |file| if File.file?(file) #判断是否是文件 #只统计.h/.m/.mm/.cpp/.swift几个文件 # if File.extname(file).match(/^.[hm]m?$|.cpp|.swift/) if File.extname(file).match(/\.(h|hpp|m|mm|cpp|swift)$/) File.read(file).each_line do |line| if line.match(/^\/\/|^$/) == nil #去掉单行注释和空行 @line_number = @line_number + 1 end end end end end return end puts "\033[31m找不到指定路径的文件或者文件夹,请重新输入路径\033[0m" end |