Class: FileAnalyzerGroup
- Inherits:
-
Object
- Object
- FileAnalyzerGroup
- Defined in:
- lib/kwala/lib/code_analyzer.rb
Instance Method Summary collapse
- #extra_summary(methods) ⇒ Object
-
#initialize(files) ⇒ FileAnalyzerGroup
constructor
A new instance of FileAnalyzerGroup.
- #print_extra_summary(name, msg, uniqs) ⇒ Object
- #print_summary_header(summary) ⇒ Object
- #summarize ⇒ Object
Constructor Details
#initialize(files) ⇒ FileAnalyzerGroup
Returns a new instance of FileAnalyzerGroup.
374 375 376 377 378 379 |
# File 'lib/kwala/lib/code_analyzer.rb', line 374 def initialize(files) @fa_files = [] files.each do |file| @fa_files<< FileAnalyzer.new(file).analyze end end |
Instance Method Details
#extra_summary(methods) ⇒ Object
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/kwala/lib/code_analyzer.rb', line 436 def extra_summary(methods) ttl_files = @fa_files.size methods.each do |mcall, mname| cnt = @fa_files.inject(0) { |cnt, f| cnt += (f.send(mcall).size > 0 ? 1 : 0) } if cnt == 0 next end msg = "#{ cnt } out of #{ ttl_files }" + " (#{sprintf("%.2f",(cnt.to_f / ttl_files) * 100)} %) use #{ mname}" uniqs = Hash.new { |h,k| h[k] = [] } @fa_files.each do |f| f.send(mcall).uniq.each do |sm| uniqs[sm] << f.file end end print_extra_summary(mname, msg, uniqs) end end |
#print_extra_summary(name, msg, uniqs) ⇒ Object
459 460 461 462 463 464 465 |
# File 'lib/kwala/lib/code_analyzer.rb', line 459 def print_extra_summary(name, msg, uniqs) puts "" , "---" + msg + "---" puts "#{name} used by files:", "" uniqs.sort.each do |k, m| puts k.to_s.ljust(30) + " -> ", " " + m.join("\n "), "" end end |
#print_summary_header(summary) ⇒ Object
429 430 431 432 433 434 |
# File 'lib/kwala/lib/code_analyzer.rb', line 429 def print_summary_header(summary) puts "Summary" summary.sort.each do |key, res| puts "#{ key.ljust(15) } : #{res}" end end |
#summarize ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/kwala/lib/code_analyzer.rb', line 381 def summarize fst = @fa_files.first vals = fst.instance_variables.map { |iv| iv[1..-1] } # remove the instance variables we set that are not related to data tracking. vals = vals - ["file", "tl_ref"] t_v = vals.map do |v| res = fst.send(v) if res.is_a?(Array) p = Proc.new { |v| v.size } else p = Proc.new { |v| v.to_i } end [v, p] end res = Hash.new { |h,k| h[k] = [] } @fa_files.each do |f| t_v.each do |method, calc| res[method]<< calc.call( f.send(method) ) end end base_sum = Hash.new(0) res.sort.each do |key, val| r = val.inject(0) { |t, v| t + v } base_sum[key] = r end print_summary_header(base_sum) extra_summary( [ ["static_methods", "static methods"], ["g_vars", "global variables"], ["c_vars", "class variables"], ["i_vars", "instance variables"], ["constants", "constants"], ["methods", "methods"], ["classes", "classes"], ["modules", "modules"], ["symbols", "symbols"], ["aliases", "aliases"], ["undefs", "undefs"] ] ) end |