Sha256: 557be5f57199b9169319fc0133bcdb9e039d162abe15dc78fe4e22046aff0b12

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module Nakal
  module Common
    class BaseScreen

      attr_accessor :image, :name

      def initialize file_name, mode = :load, image = nil
        @name = file_name
        if mode.eql?(:capture)
          capture
          load_image_from_file
        elsif mode.eql?(:load)
          load_image_from_file
        else
          @image=image
        end
      end

      def strip
        crop_params = Nakal.default_crop_params[Nakal.device_name]
        if crop_params.nil?
          @image
        else
          width = @image.columns
          height = @image.rows
          x_start = crop_params["left"]
          y_start = crop_params["top"]
          width_to_consider = width-crop_params["right"]-x_start
          height_to_consider = height-crop_params["bottom"]-y_start
          @image.crop(x_start, y_start, width_to_consider, height_to_consider)
        end
      end

      def compare screen
        diff_img, diff_metric = self.strip.compare_channel(screen.strip, Magick::RootMeanSquaredErrorMetric)
        diff_screen = Nakal.current_platform::Screen.new("#{@name}_diff", :none, diff_img)
        return diff_screen, diff_metric
      end

      def delete!
        FileUtils.rm "#{Nakal.image_location}/#{@name}.png"
      end

      def save
        @image.write("#{Nakal.image_location}/#{@name}.png")
      end

      private

      def load_image_from_file
        @image = Magick::Image.read("#{Nakal.image_location}/#{@name}.png")[0]
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nakal-0.0.1 lib/nakal/base_screen.rb