Sha256: 7311f4562a58ae2428345ad4362978a6525fef1aa1ede936270fc5bf38f64f70

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require "chunky_png"
require "capybara/screenshot/diff/difference"

module Capybara
  module Screenshot
    module Diff
      # Compare two images and determine if they are equal, different, or within some comparison
      # range considering color values and difference area size.
      module Drivers
        class BaseDriver
          PNG_EXTENSION = ".png"

          def same_dimension?(comparison)
            dimension(comparison.base_image) == dimension(comparison.new_image)
          end

          def height_for(image)
            image.height
          end

          def width_for(image)
            image.width
          end

          def image_area_size(image)
            width_for(image) * height_for(image)
          end

          def dimension(image)
            [width_for(image), height_for(image)]
          end

          def inscribed?(dimensions, i)
            width_for(i) < dimensions[0] || height_for(i) < dimensions[1]
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
capybara-screenshot-diff-1.8.3 lib/capybara/screenshot/diff/drivers/base_driver.rb
capybara-screenshot-diff-1.8.2 lib/capybara/screenshot/diff/drivers/base_driver.rb
capybara-screenshot-diff-1.8.1 lib/capybara/screenshot/diff/drivers/base_driver.rb
capybara-screenshot-diff-1.8.0 lib/capybara/screenshot/diff/drivers/base_driver.rb