Class: Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/visual_matcher/matcher.rb

Instance Method Summary collapse

Instance Method Details

#compare_screens(images, acceptant_criteria) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/visual_matcher/matcher.rb', line 5

def compare_screens(images, acceptant_criteria)
  if Image.sizes_match?(images)
    raise SizesMismatchError,
          "can't compare images with different sizes"
  end

  diff = []
  images[0].height.times do |y|
    images[0].row(y).each_with_index do |pixel, x|
      diff << [x, y] unless pixel == images[1][x, y]
    end
  end

  x = diff.map { |xy| xy[0] }
  y = diff.map { |xy| xy[1] }
  DiffResult.save_diff(images.last.rect(x.min, y.min, x.max, x.min,
                                        ChunkyPNG::Color::BLACK))
  DiffResult.calculate_score(diff, images, acceptant_criteria)
end