Class: Applitools::Images::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/applitools/images/target.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image) ⇒ Target

Returns a new instance of Target.



47
48
49
50
51
52
53
54
55
# File 'lib/applitools/images/target.rb', line 47

def initialize(image)
  Applitools::ArgumentGuard.not_nil(image, 'image')
  Applitools::ArgumentGuard.is_a? image, 'image', Applitools::Screenshot
  self.image = image
  self.ignored_regions = []
  self.options = {
    trim: false
  }
end

Instance Attribute Details

#ignored_regionsObject

Returns the value of attribute ignored_regions.



45
46
47
# File 'lib/applitools/images/target.rb', line 45

def ignored_regions
  @ignored_regions
end

#imageObject

Returns the value of attribute image.



45
46
47
# File 'lib/applitools/images/target.rb', line 45

def image
  @image
end

#optionsObject

Returns the value of attribute options.



45
46
47
# File 'lib/applitools/images/target.rb', line 45

def options
  @options
end

#region_to_checkObject

Returns the value of attribute region_to_check.



45
46
47
# File 'lib/applitools/images/target.rb', line 45

def region_to_check
  @region_to_check
end

Class Method Details

.any(screenshot) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/applitools/images/target.rb', line 27

def any(screenshot)
  case screenshot
  when Applitools::Screenshot
    screenshot(screenshot)
  when ChunkyPNG::Image
    image(screenshot)
  when String
    begin
      blob(screenshot)
    rescue ChunkyPNG::SignatureMismatch
      path(screenshot)
    end
  else
    raise Applitools::EyesIllegalArgument.new "Passed screenshot is not image type (#{screenshot.class})"
  end
end

.blob(blob_image) ⇒ Object



9
10
11
12
13
# File 'lib/applitools/images/target.rb', line 9

def blob(blob_image)
  Applitools::ArgumentGuard.not_nil blob_image, 'blob_image'
  Applitools::ArgumentGuard.is_a? blob_image, 'blob_image', String
  new Applitools::Screenshot.from_datastream(blob_image)
end

.image(image) ⇒ Object



15
16
17
18
19
# File 'lib/applitools/images/target.rb', line 15

def image(image)
  Applitools::ArgumentGuard.not_nil image, 'image'
  Applitools::ArgumentGuard.is_a? image, 'image', ChunkyPNG::Image
  new Applitools::Screenshot.from_image(image)
end

.path(path) ⇒ Object

Raises:

  • (Applitools::EyesIllegalArgument)


4
5
6
7
# File 'lib/applitools/images/target.rb', line 4

def path(path)
  raise Applitools::EyesIllegalArgument unless File.exist?(path)
  new Applitools::Screenshot.from_image(ChunkyPNG::Image.from_file(path))
end

.screenshot(screenshot) ⇒ Object



21
22
23
24
25
# File 'lib/applitools/images/target.rb', line 21

def screenshot(screenshot)
  Applitools::ArgumentGuard.not_nil screenshot, 'screenshot'
  Applitools::ArgumentGuard.is_a? screenshot, 'screenshot', Applitools::Screenshot
  new screenshot
end

Instance Method Details

#ignore(region = nil) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/applitools/images/target.rb', line 57

def ignore(region = nil)
  if region
    Applitools::ArgumentGuard.is_a? region, 'region', Applitools::Region
    ignored_regions << region
  else
    self.ignored_regions = []
  end
  self
end

#region(region = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/applitools/images/target.rb', line 67

def region(region = nil)
  if region
    Applitools::ArgumentGuard.is_a? region, 'region', Applitools::Region
    self.region_to_check = region
  else
    self.region_to_check = nil
  end
  self
end

#timeout(value = nil) ⇒ Object



82
83
84
85
# File 'lib/applitools/images/target.rb', line 82

def timeout(value = nil)
  options[:timeout] = value ? value : nil
  self
end

#trim(value = true) ⇒ Object



77
78
79
80
# File 'lib/applitools/images/target.rb', line 77

def trim(value = true)
  options[:trim] = value ? true : false
  self
end