Skip to content
Browse files

Update examples

  • Loading branch information...
1 parent face1db commit 217ada81ea8e23ee736ff9ebf94a90a9f8e93b0a @lsegal committed
Showing with 63 additions and 1 deletion.
  1. +2 −0 .gitignore
  2. +1 −1 mmmail
  3. +60 −0 sloc.rb
View
2 .gitignore
@@ -0,0 +1,2 @@
+.yardoc
+doc/
2 mmmail
@@ -1 +1 @@
-Subproject commit f7fbf0b94d192c20e3e90a4c2f2929b96400dc0c
+Subproject commit b876796a995ae353a7c3faed551f8c0b019e0444
View
60 sloc.rb
@@ -0,0 +1,60 @@
+require 'yard'
+include YARD::Parser
+
+file = ARGV[0] || __FILE__
+
+$sloc, $cloc = 0, 0
+class SLOC
+ attr_accessor :files
+
+ def initialize(*args)
+ SourceParser.parser_type = :ruby18
+ self.files = {}
+ log.enter_level(Logger::FATAL) do
+ args.each do |file|
+ files[file] = {sloc:0, cloc:0}
+ parse_string(file, IO.read(file))
+
+ print_file(file)
+ end
+
+ print_totals
+ end
+ end
+
+ def parse(file, stmts)
+ stmts.each do |stmt|
+ files[file][:sloc] += 1
+ files[file][:cloc] += stmt.comments.size if stmt.comments
+ parse_string(file, stmt.block.to_s) if stmt.block
+ end
+ end
+
+ def parse_string(file, str)
+ parse(file, YARD::Parser::SourceParser.parse_string(str))
+ end
+
+ def print_file(file)
+ puts "#{file}:"
+ puts "SLOC: #{files[file][:sloc]}"
+ puts "CLOC: #{files[file][:cloc]}"
+ puts
+ end
+
+ def print_totals
+ total_sloc, total_cloc = 0, 0
+ avg_sloc, avg_cloc = 0, 0
+ files.each do |file, v|
+ total_sloc += v[:sloc]
+ total_cloc += v[:cloc]
+ end
+ avg_sloc = total_sloc.to_f / files.size
+ avg_cloc = total_cloc.to_f / files.size
+ puts "Totals:"
+ puts "SLOC (avg): ~#{avg_sloc.round} per file"
+ puts "CLOC (avg): ~#{avg_cloc.round} per file"
+ end
+end
+
+files = ARGV.empty? ? [__FILE__] : ARGV
+SLOC.new(*files)

0 comments on commit 217ada8

Please sign in to comment.
Something went wrong with that request. Please try again.