Class: DotDiff::ThresholdCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/dotdiff/threshold_calculator.rb

Constant Summary collapse

PIXEL =
'pixel'
PERCENT =
'percent'

Instance Method Summary collapse

Constructor Details

#initialize(threshold_config, total_pixels, pixel_diff) ⇒ ThresholdCalculator

Returns a new instance of ThresholdCalculator.



8
9
10
11
12
# File 'lib/dotdiff/threshold_calculator.rb', line 8

def initialize(threshold_config, total_pixels, pixel_diff)
  @threshold_config = threshold_config
  @total_pixels = total_pixels
  @pixel_diff = pixel_diff
end

Instance Method Details

#messageObject



29
30
31
# File 'lib/dotdiff/threshold_calculator.rb', line 29

def message
  "Outcome was '#{value}' difference for type '#{threshold_type}'"
end

#under_threshold?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dotdiff/threshold_calculator.rb', line 14

def under_threshold?
  return false if total_pixels.nil? || pixel_diff.nil?

  case threshold_type
  when PIXEL
    @value = pixel_diff
  when PERCENT
    @value = pixel_diff / total_pixels.to_f
  else
    raise UnknownTypeError, "Unable to handle threshold type: #{threshold_type}"
  end

  value <= threshold_value
end