Class: Capybara::Screenshot::Diff::ImageCompare
- Inherits:
-
Object
- Object
- Capybara::Screenshot::Diff::ImageCompare
- Includes:
- ChunkyPNG::Color
- Defined in:
- lib/capybara/screenshot/diff/image_compare.rb
Class Method Summary collapse
Instance Method Summary collapse
- #compare ⇒ Object
- #dimensions ⇒ Object
-
#initialize(old_file_name, new_file_name, dimensions = nil) ⇒ ImageCompare
constructor
A new instance of ImageCompare.
Constructor Details
#initialize(old_file_name, new_file_name, dimensions = nil) ⇒ ImageCompare
Returns a new instance of ImageCompare.
13 14 15 16 17 |
# File 'lib/capybara/screenshot/diff/image_compare.rb', line 13 def initialize(old_file_name, new_file_name, dimensions = nil) @old_file_name = old_file_name @file_name = new_file_name @dimensions = dimensions end |
Class Method Details
.compare(*args) ⇒ Object
9 10 11 |
# File 'lib/capybara/screenshot/diff/image_compare.rb', line 9 def self.compare(*args) new(*args).compare end |
Instance Method Details
#compare ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/capybara/screenshot/diff/image_compare.rb', line 19 def compare name = @file_name.chomp('.png') org_file_name = "#{name}_0.png~" new_file_name = "#{name}_1.png~" return nil unless File.exist? @old_file_name images = load_images(@old_file_name, @file_name) unless images clean_tmp_files(new_file_name, org_file_name) return false end crop_images(images, @dimensions) if @dimensions org_img = images.first new_img = images.last if sizes_changed?(org_img, new_img, name) save_images(new_file_name, new_img, org_file_name, org_img) return true end if org_img.pixels == new_img.pixels clean_tmp_files(new_file_name, org_file_name) return false end @left, @top, @right, @bottom = find_diff_rectangle(org_img, new_img) draw_rectangles(images, @bottom, @left, @right, @top) save_images(new_file_name, new_img, org_file_name, org_img) true end |
#dimensions ⇒ Object
52 53 54 |
# File 'lib/capybara/screenshot/diff/image_compare.rb', line 52 def dimensions [@left, @top, @right, @bottom] end |