Class: DotDiff::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/dotdiff/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Image

Returns a new instance of Image.



7
8
9
10
11
12
13
# File 'lib/dotdiff/image.rb', line 7

def initialize(opts = {})
  Hash(opts).each do |key, value|
    if self.respond_to?("#{key}=")
      self.send("#{key}=", value)
    end
  end
end

Instance Attribute Details

#driverObject

Returns the value of attribute driver.



5
6
7
# File 'lib/dotdiff/image.rb', line 5

def driver
  @driver
end

#file_nameObject

Returns the value of attribute file_name.



5
6
7
# File 'lib/dotdiff/image.rb', line 5

def file_name
  @file_name
end

#resave_base_imageObject

Returns the value of attribute resave_base_image.



5
6
7
# File 'lib/dotdiff/image.rb', line 5

def resave_base_image
  @resave_base_image
end

#subdirObject

Returns the value of attribute subdir.



5
6
7
# File 'lib/dotdiff/image.rb', line 5

def subdir
  @subdir
end

Instance Method Details

#base_image_fileObject



45
46
47
48
49
# File 'lib/dotdiff/image.rb', line 45

def base_image_file
  @file_name = "#{file_name}.png" unless file_name.include?('.png')

  File.join(DotDiff.image_store_path, subdir.to_s, file_name)
end

#compareObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dotdiff/image.rb', line 15

def compare
  outcome = []

  if !File.exists?(base_image_file) || resave_base_image
    path = capture_and_resave_base_image
    outcome = [true, path]
  else
    compare_to_image = capture_from_browser
    result = CommandWrapper.new

    result.run(base_image_file, compare_to_image)

    if result.failed? && DotDiff.failure_image_path
      FileUtils.mkdir_p(File.join(DotDiff.failure_image_path, subdir.to_s))
      file_name = File.basename(compare_to_image)

      FileUtils.mv(compare_to_image,
        File.join(DotDiff.failure_image_path, subdir.to_s, file_name), force: true)
    end

    outcome = [result.passed?, result.message]
  end

  outcome
end