Class: HighWaterMark::Threshold

Inherits:
Object
  • Object
show all
Defined in:
lib/high_water_mark/threshold.rb

Overview

Calculate threshold for quality gem tool

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool_name, count_file: File, count_io: IO, output_dir: 'metrics') ⇒ Threshold

Returns a new instance of Threshold.



8
9
10
11
12
13
14
15
16
# File 'lib/high_water_mark/threshold.rb', line 8

def initialize(tool_name,
               count_file: File,
               count_io: IO,
               output_dir: 'metrics')
  @tool_name = tool_name
  @count_file = count_file
  @count_io = count_io
  @filename = File.join(output_dir, "#{tool_name}_high_water_mark")
end

Instance Attribute Details

#tool_nameObject (readonly)

Returns the value of attribute tool_name.



6
7
8
# File 'lib/high_water_mark/threshold.rb', line 6

def tool_name
  @tool_name
end

Instance Method Details

#thresholdObject



18
19
20
# File 'lib/high_water_mark/threshold.rb', line 18

def threshold
  return @count_io.read(@filename).to_i if @count_file.exist?(@filename)
end

#write_violations(new_violations) ⇒ Object



22
23
24
25
26
# File 'lib/high_water_mark/threshold.rb', line 22

def write_violations(new_violations)
  @count_file.open(@filename, 'w') do |file|
    file.write(new_violations.to_s + "\n")
  end
end