Sha256: 789cae5ae1ecc46cdff76bd9d1a37c0fbdc1669a45f0298816a1c96b6d569948

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require "json"

module Capybara
  module Screenshot
    module Diff
      class Difference < Struct.new(:region, :meta, :comparison)
        def different?
          !(blank? || tolerable?)
        end

        def base_image
          comparison.base_image
        end

        def options
          comparison.options
        end

        def tolerance
          options[:tolerance]
        end

        def skip_area
          options[:skip_area]
        end

        def area_size_limit
          options[:area_size_limit]
        end

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

        def region_area_size
          region&.size || 0
        end

        def ratio
          meta[:difference_level]
        end

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

        def coordinates
          region&.to_edge_coordinates
        end

        def inspect
          to_h.to_json
        end

        def tolerable?
          !!((area_size_limit && area_size_limit >= region_area_size) || (tolerance && tolerance >= ratio))
        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/difference.rb
capybara-screenshot-diff-1.8.2 lib/capybara/screenshot/diff/difference.rb
capybara-screenshot-diff-1.8.1 lib/capybara/screenshot/diff/difference.rb
capybara-screenshot-diff-1.8.0 lib/capybara/screenshot/diff/difference.rb