Class: Applitools::Images::Target

Inherits:
Object
  • Object
show all
Includes:
FluentInterface
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.


50
51
52
53
54
55
56
57
58
59
60
# File 'lib/applitools/images/target.rb', line 50

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

Instance Attribute Details

#accessibility_regionsObject

Returns the value of attribute accessibility_regions


48
49
50
# File 'lib/applitools/images/target.rb', line 48

def accessibility_regions
  @accessibility_regions
end

#floating_regionsObject

Returns the value of attribute floating_regions


48
49
50
# File 'lib/applitools/images/target.rb', line 48

def floating_regions
  @floating_regions
end

#ignored_regionsObject

Returns the value of attribute ignored_regions


48
49
50
# File 'lib/applitools/images/target.rb', line 48

def ignored_regions
  @ignored_regions
end

#imageObject

Returns the value of attribute image


48
49
50
# File 'lib/applitools/images/target.rb', line 48

def image
  @image
end

#optionsObject

Returns the value of attribute options


48
49
50
# File 'lib/applitools/images/target.rb', line 48

def options
  @options
end

#region_to_checkObject

Returns the value of attribute region_to_check


48
49
50
# File 'lib/applitools/images/target.rb', line 48

def region_to_check
  @region_to_check
end

Class Method Details

.any(screenshot) ⇒ Object


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

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


12
13
14
15
16
# File 'lib/applitools/images/target.rb', line 12

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


18
19
20
21
22
# File 'lib/applitools/images/target.rb', line 18

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)

7
8
9
10
# File 'lib/applitools/images/target.rb', line 7

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

.screenshot(screenshot) ⇒ Object


24
25
26
27
28
# File 'lib/applitools/images/target.rb', line 24

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

Instance Method Details

#accesibility(*args) ⇒ Object


110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/applitools/images/target.rb', line 110

def accesibility(*args)
  accessibility_regions << case args.first
                           when Applitools::AccessibilityRegion
                             args.first
                           when Applitools::Region
                             Applitools::AccessibilityRegion.new(args.first, args.last)
                           else
                             accessibility_region_type = args.pop
                             region = Applitools::Region.new(*args)
                             Applitools::AccessibilityRegion.new(region, accessibility_region_type)
                           end
end

#floating(*args) ⇒ Object


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/applitools/images/target.rb', line 78

def floating(*args)
  requested_padding = if args.last.is_a? Applitools::PaddingBounds
                        args.pop
                      else
                        Applitools::PaddingBounds::PIXEL_PADDING
                      end

  value = case args.first
          when Applitools::FloatingRegion
            proc { args.first.padding(requested_padding) }
          when Applitools::Region
            proc do
              region = args.shift
              Applitools::FloatingRegion.any(region, *args).padding(requested_padding)
            end
          else
            self.floating_regions = []
          end
  floating_regions << value
  self
end

#ignore(*args) ⇒ Object


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/applitools/images/target.rb', line 62

def ignore(*args)
  requested_padding = if args.last.is_a? Applitools::PaddingBounds
                        args.pop
                      else
                        Applitools::PaddingBounds::PIXEL_PADDING
                      end
  region = args.shift
  if region
    Applitools::ArgumentGuard.is_a? region, 'region', Applitools::Region
    ignored_regions << region.padding(requested_padding)
  else
    self.ignored_regions = []
  end
  self
end

#region(region = nil) ⇒ Object


100
101
102
103
104
105
106
107
108
# File 'lib/applitools/images/target.rb', line 100

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