Class: SnapDiff::Reporters::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/snap_diff/reporters/default.rb

Constant Summary collapse

NEW_LINE =
"\n"
THRESHOLDS =

The thresholds a comparison is judged against, in the order they read best. Only the ones actually set are printed -- see #thresholds.

[
  :tolerance,
  :area_size_limit,
  :color_distance_limit,
  :shift_distance_limit,
  :perceptual_threshold
].freeze
ARTIFACT_LABELS =

The five artifacts a comparison can leave on disk, in the order a reader wants them: the two inputs first, then what we drew on them.

{
  "baseline" => :base_image_path,
  "actual" => :image_path,
  "baseline annotated" => :annotated_base_image_path,
  "actual annotated" => :annotated_image_path,
  "heatmap" => :heatmap_diff_path
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(difference) ⇒ Default

Returns a new instance of Default.



14
15
16
17
# File 'lib/snap_diff/reporters/default.rb', line 14

def initialize(difference)
  @difference = difference
  @annotation_service = SnapDiff::AnnotationService.new(difference)
end

Instance Attribute Details

#differenceObject (readonly)

Returns the value of attribute difference.



12
13
14
# File 'lib/snap_diff/reporters/default.rb', line 12

def difference
  @difference
end

Instance Method Details

#annotate_and_save_imagesObject



50
51
52
# File 'lib/snap_diff/reporters/default.rb', line 50

def annotate_and_save_images
  annotation_service.annotate_and_save_images
end

#annotated_base_image_pathObject



23
24
25
# File 'lib/snap_diff/reporters/default.rb', line 23

def annotated_base_image_path
  annotation_service.annotated_base_image_path
end

#annotated_image_pathObject



19
20
21
# File 'lib/snap_diff/reporters/default.rb', line 19

def annotated_image_path
  annotation_service.annotated_image_path
end

#build_error_for_different_dimensionsObject



54
55
56
57
58
59
60
# File 'lib/snap_diff/reporters/default.rb', line 54

def build_error_for_different_dimensions
  change_msg = [comparison.base_image, comparison.new_image]
    .map { |image| driver.dimension(image).join("x") }
    .join(" => ")

  "Dimensions have changed: #{change_msg}\n#{base_image_path.to_path}\n#{image_path.to_path}"
end

#build_error_messageObject



84
85
86
# File 'lib/snap_diff/reporters/default.rb', line 84

def build_error_message
  [headline, *metric_lines, *artifact_lines].join(NEW_LINE)
end

#clean_tmp_filesObject



46
47
48
# File 'lib/snap_diff/reporters/default.rb', line 46

def clean_tmp_files
  annotation_service.clean_tmp_files
end

#generateObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/snap_diff/reporters/default.rb', line 31

def generate
  if difference.equal?
    # NOTE: Delete previous run runtime files
    clean_tmp_files
    return nil
  end

  if difference.failed? && difference.failed_by[:different_dimensions]
    return build_error_for_different_dimensions
  end

  annotate_and_save_images
  build_error_message
end

#heatmap_diff_pathObject



27
28
29
# File 'lib/snap_diff/reporters/default.rb', line 27

def heatmap_diff_path
  annotation_service.heatmap_diff_path
end