Class: Capybara::Screenshot::Diff::Difference

Inherits:
Struct
  • Object
show all
Defined in:
lib/capybara/screenshot/diff/difference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#comparisonObject

Returns the value of attribute comparison

Returns:

  • (Object)

    the current value of comparison



8
9
10
# File 'lib/capybara/screenshot/diff/difference.rb', line 8

def comparison
  @comparison
end

#failed_byObject

Returns the value of attribute failed_by

Returns:

  • (Object)

    the current value of failed_by



8
9
10
# File 'lib/capybara/screenshot/diff/difference.rb', line 8

def failed_by
  @failed_by
end

#metaObject

Returns the value of attribute meta

Returns:

  • (Object)

    the current value of meta



8
9
10
# File 'lib/capybara/screenshot/diff/difference.rb', line 8

def meta
  @meta
end

#regionObject

Returns the value of attribute region

Returns:

  • (Object)

    the current value of region



8
9
10
# File 'lib/capybara/screenshot/diff/difference.rb', line 8

def region
  @region
end

Instance Method Details

#area_size_limitObject



33
34
35
# File 'lib/capybara/screenshot/diff/difference.rb', line 33

def area_size_limit
  options[:area_size_limit]
end

#blank?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/capybara/screenshot/diff/difference.rb', line 37

def blank?
  region.nil? || region_area_size.zero?
end

#coordinatesObject



53
54
55
# File 'lib/capybara/screenshot/diff/difference.rb', line 53

def coordinates
  region&.to_edge_coordinates
end

#different?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/capybara/screenshot/diff/difference.rb', line 9

def different?
  failed? || !(blank? || tolerable?)
end

#equal?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/capybara/screenshot/diff/difference.rb', line 13

def equal?
  !different?
end

#failed?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/capybara/screenshot/diff/difference.rb', line 17

def failed?
  !!failed_by
end

#inspectObject



57
58
59
# File 'lib/capybara/screenshot/diff/difference.rb', line 57

def inspect
  to_h.to_json
end

#optionsObject



21
22
23
# File 'lib/capybara/screenshot/diff/difference.rb', line 21

def options
  comparison.options
end

#ratioObject



45
46
47
# File 'lib/capybara/screenshot/diff/difference.rb', line 45

def ratio
  meta[:difference_level]
end

#region_area_sizeObject



41
42
43
# File 'lib/capybara/screenshot/diff/difference.rb', line 41

def region_area_size
  region&.size || 0
end

#skip_areaObject



29
30
31
# File 'lib/capybara/screenshot/diff/difference.rb', line 29

def skip_area
  options[:skip_area]
end

#to_hObject



49
50
51
# File 'lib/capybara/screenshot/diff/difference.rb', line 49

def to_h
  {area_size: region_area_size, region: coordinates}.merge!(meta)
end

#tolerable?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/capybara/screenshot/diff/difference.rb', line 61

def tolerable?
  !!((area_size_limit && area_size_limit >= region_area_size) || (tolerance && tolerance >= ratio))
end

#toleranceObject



25
26
27
# File 'lib/capybara/screenshot/diff/difference.rb', line 25

def tolerance
  options[:tolerance]
end