Class: SnapDiff::ComparisonResult
- Inherits:
-
Struct
- Object
- Struct
- SnapDiff::ComparisonResult
- Defined in:
- lib/snap_diff/comparison_result.rb
Overview
Represents the result of comparing two images
This value object encapsulates the result of an image comparison operation. It follows the Single Responsibility Principle by focusing solely on representing the difference state, including:
- Whether images are different or equal
- Why they differ (dimensions, pixels, etc.)
- The specific region of difference
- Whether differences are tolerable based on configured thresholds
As part of the layered comparison architecture, this class represents the final output of the comparison process, containing all data needed for reporting.
Instance Attribute Summary collapse
-
#base_image_path ⇒ Object
Returns the value of attribute base_image_path.
-
#comparison ⇒ Object
Returns the value of attribute comparison.
-
#failed_by ⇒ Object
Returns the value of attribute failed_by.
-
#image_path ⇒ Object
Returns the value of attribute image_path.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#region ⇒ Object
Returns the value of attribute region.
Class Method Summary collapse
Instance Method Summary collapse
- #area_size_limit ⇒ Object
- #blank? ⇒ Boolean
- #coordinates ⇒ Object
- #diff_mask ⇒ Object
- #different? ⇒ Boolean
- #equal? ⇒ Boolean
- #failed? ⇒ Boolean
-
#inspect ⇒ Object
One-line debugging summary with the difference metrics.
-
#new_image_path ⇒ Object
Path accessors for backward compatibility.
- #options ⇒ Object
- #original_image_path ⇒ Object
- #ratio ⇒ Object
- #region_area_size ⇒ Object
- #skip_area ⇒ Object
-
#to_h ⇒ Object
Serializable difference metrics.
- #tolerable? ⇒ Boolean
- #tolerance ⇒ Object
Instance Attribute Details
#base_image_path ⇒ Object
Returns the value of attribute base_image_path
18 19 20 |
# File 'lib/snap_diff/comparison_result.rb', line 18 def base_image_path @base_image_path end |
#comparison ⇒ Object
Returns the value of attribute comparison
18 19 20 |
# File 'lib/snap_diff/comparison_result.rb', line 18 def comparison @comparison end |
#failed_by ⇒ Object
Returns the value of attribute failed_by
18 19 20 |
# File 'lib/snap_diff/comparison_result.rb', line 18 def failed_by @failed_by end |
#image_path ⇒ Object
Returns the value of attribute image_path
18 19 20 |
# File 'lib/snap_diff/comparison_result.rb', line 18 def image_path @image_path end |
#meta ⇒ Object
Returns the value of attribute meta
18 19 20 |
# File 'lib/snap_diff/comparison_result.rb', line 18 def @meta end |
#region ⇒ Object
Returns the value of attribute region
18 19 20 |
# File 'lib/snap_diff/comparison_result.rb', line 18 def region @region end |
Class Method Details
.build_null(comparison, base_image_path, new_image_path, failed_by = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/snap_diff/comparison_result.rb', line 19 def self.build_null(comparison, base_image_path, new_image_path, failed_by = nil) ComparisonResult.new( nil, {difference_level: nil, max_color_distance: 0}, comparison, failed_by, base_image_path, new_image_path ).freeze end |
Instance Method Details
#area_size_limit ⇒ Object
54 55 56 |
# File 'lib/snap_diff/comparison_result.rb', line 54 def area_size_limit [:area_size_limit] end |
#blank? ⇒ Boolean
58 59 60 |
# File 'lib/snap_diff/comparison_result.rb', line 58 def blank? region.nil? || region_area_size.zero? end |
#coordinates ⇒ Object
76 77 78 |
# File 'lib/snap_diff/comparison_result.rb', line 76 def coordinates region&.to_edge_coordinates end |
#diff_mask ⇒ Object
102 103 104 |
# File 'lib/snap_diff/comparison_result.rb', line 102 def diff_mask [:diff_mask] end |
#different? ⇒ Boolean
30 31 32 |
# File 'lib/snap_diff/comparison_result.rb', line 30 def different? failed? || !(blank? || tolerable?) end |
#equal? ⇒ Boolean
34 35 36 |
# File 'lib/snap_diff/comparison_result.rb', line 34 def equal? !different? end |
#failed? ⇒ Boolean
38 39 40 |
# File 'lib/snap_diff/comparison_result.rb', line 38 def failed? !!failed_by end |
#inspect ⇒ Object
One-line debugging summary with the difference metrics. (Error messages use #to_h — see Reporters::Default#build_error_message.)
82 83 84 85 86 87 |
# File 'lib/snap_diff/comparison_result.rb', line 82 def inspect "#<#{self.class.name} different=#{different?} failed_by=#{failed_by.inspect} " \ "area_size=#{region_area_size} region=#{coordinates.inspect} " \ "difference_level=#{ratio.inspect} " \ "base=#{original_image_path} new=#{new_image_path}>" end |
#new_image_path ⇒ Object
Path accessors for backward compatibility
94 95 96 |
# File 'lib/snap_diff/comparison_result.rb', line 94 def new_image_path image_path || comparison&.new_image_path end |
#options ⇒ Object
42 43 44 |
# File 'lib/snap_diff/comparison_result.rb', line 42 def comparison. end |
#original_image_path ⇒ Object
98 99 100 |
# File 'lib/snap_diff/comparison_result.rb', line 98 def original_image_path base_image_path || comparison&.base_image_path end |
#ratio ⇒ Object
66 67 68 |
# File 'lib/snap_diff/comparison_result.rb', line 66 def ratio [:difference_level] end |
#region_area_size ⇒ Object
62 63 64 |
# File 'lib/snap_diff/comparison_result.rb', line 62 def region_area_size @region_area_size ||= region&.size || 0 end |
#skip_area ⇒ Object
50 51 52 |
# File 'lib/snap_diff/comparison_result.rb', line 50 def skip_area comparison.skip_area end |
#to_h ⇒ Object
Serializable difference metrics. The raw diff mask image is excluded — it is an image object, not a metric, and is reachable via #diff_mask.
72 73 74 |
# File 'lib/snap_diff/comparison_result.rb', line 72 def to_h {area_size: region_area_size, region: coordinates}.merge!(.except(:diff_mask)) end |
#tolerable? ⇒ Boolean
89 90 91 |
# File 'lib/snap_diff/comparison_result.rb', line 89 def tolerable? !!((area_size_limit && area_size_limit >= region_area_size) || (tolerance && tolerance >= ratio)) end |
#tolerance ⇒ Object
46 47 48 |
# File 'lib/snap_diff/comparison_result.rb', line 46 def tolerance [:tolerance] end |