Sha256: 2362ac8c55cb51b5687aabdbc7bb02f66d22b52b43fa2ff4090963529d918aff

Contents?: true

Size: 1007 Bytes

Versions: 1

Compression:

Stored size: 1007 Bytes

Contents

module Gatling
  class Image

    attr_accessor :file_name, :path, :image

    attr_reader :type

    def initialize(type, file_name, element_or_image = nil)

      @file_name = file_name

      case type
      when :from_file
        @image = image_from_file(file_name)
      when :from_element
        @image = image_from_element(element_or_image)
      when :from_diff
        @image = element_or_image
      else
        raise 'WRONG IMAGE TYPE'
      end

    end

    def save type
      @path = File.join(Gatling::Configuration.path_from_type(type[:as]), @file_name)
      @image.write @path
      @path
    end

    def exists?
      File.exists?(File.join(Gatling::Configuration.path_from_type(:reference), @file_name))
    end

    private

    def image_from_element element
      Gatling::CaptureElement.new(element).capture
    end

    def image_from_file file_name
      Magick::Image.read(File.join(Gatling::Configuration.path_from_type(:reference), file_name)).first
    end


  end

end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gatling-1.0.7 lib/gatling/image.rb