Class: HomeWorkChecker::TestRunStat::RubyStat

Inherits:
Object
  • Object
show all
Defined in:
lib/hw_checker/ruby_stat.rb

Instance Method Summary collapse

Constructor Details

#initialize(tmp_path, dirname) ⇒ RubyStat

Returns a new instance of RubyStat.



4
5
6
7
# File 'lib/hw_checker/ruby_stat.rb', line 4

def initialize(tmp_path, dirname)
  @tmp_path, @dirname= tmp_path, dirname
  @lines_all = @lines_failed = 0
end

Instance Method Details

#calc_percent_qualityObject



32
33
34
35
# File 'lib/hw_checker/ruby_stat.rb', line 32

def calc_percent_quality
  return 0.00 if @lines_all.zero?
  ( (1.0 - @lines_failed.to_f / @lines_all) * 100).round(2)
end

#count_lines_all(filename) ⇒ Object



28
29
30
# File 'lib/hw_checker/ruby_stat.rb', line 28

def count_lines_all(filename)
  File.open(filename).each_line { @lines_all += 1 }        
end

#count_lines_failed(filename) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/hw_checker/ruby_stat.rb', line 19

def count_lines_failed(filename)
  temp = []
  File.open(filename).each_line do |line|
    next unless line.match(/[CW]:\s+\d+:\s+[\w\W]{4,}/)
    temp << line.scan(/\d+/).first.to_i
  end
  @lines_failed += temp.uniq.size
end

#performObject



9
10
11
12
13
14
15
16
17
# File 'lib/hw_checker/ruby_stat.rb', line 9

def perform
  Dir.foreach("#{@tmp_path}/#{@dirname}") do |p|
    next unless File::file?("#{@tmp_path}/#{@dirname}/#{p}") && File.extname(p) == '.rb'
    `rubocop #{@tmp_path}/#{@dirname}/#{p} > #{@tmp_path}/#{@dirname}/#{p}.tmp`
    count_lines_failed("#{@tmp_path}/#{@dirname}/#{p}.tmp")
    count_lines_all("#{@tmp_path}/#{@dirname}/#{p}")
  end
  calc_percent_quality
end