Class: Applitools::FloatingRegion

Inherits:
Region
  • Object
show all
Defined in:
lib/applitools/core/floating_region.rb

Constant Summary collapse

NAMES =
[
  :left, :top, :width, :height, :max_left_offset, :max_top_offset, :max_right_offset, :max_bottom_offset
].freeze

Constants inherited from Region

Region::EMPTY

Instance Attribute Summary collapse

Attributes inherited from Region

#height, #left, #top, #width

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Region

#bottom, #contains?, #empty?, from_location_size, #intersect, #intersecting?, #location, #location=, #make_empty, #middle_offset, #padding, #right, #size, #size_equals?, #sub_regions, sub_regions_with_fixed_size, sub_regions_with_varying_size, #to_s, #with_padding

Constructor Details

#initialize(*args) ⇒ FloatingRegion

Returns a new instance of FloatingRegion.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/applitools/core/floating_region.rb', line 40

def initialize(*args)
  case args.size
  when 2
    region = args.first
    bounds = args.last
    super(region.left, region.top, region.width, region.height)
    self.max_left_offset = bounds.max_left_offset
    self.max_top_offset = bounds.max_top_offset
    self.max_right_offset = bounds.max_right_offset
    self.max_bottom_offset = bounds.max_bottom_offset
  when 8
    args.each_with_index do |a, i|
      Applitools::ArgumentGuard.is_a? a, NAMES[i], Integer
      Applitools::ArgumentGuard.greater_than_or_equal_to_zero(a, NAMES[i])
    end
    super(*args[0..3])
    self.max_left_offset = args[4]
    self.max_top_offset = args[5]
    self.max_right_offset = args[6]
    self.max_bottom_offset = args[7]
  else
    raise(
      Applitools::EyesIllegalArgument,
      'Expected Applitools::FloatingRegion.new to be called as ' \
         'Applitools::FloatingRegion.new(region, floating_bounds)' \
         'or ' \
         'Applitools::FloatingRegion.new(left, top, width, height, ' \
         'bounds_leeft, bounds_top, bounds_right, bounds_bottom)'
    )
  end
end

Instance Attribute Details

#max_bottom_offsetObject

Returns the value of attribute max_bottom_offset.



34
35
36
# File 'lib/applitools/core/floating_region.rb', line 34

def max_bottom_offset
  @max_bottom_offset
end

#max_left_offsetObject

Returns the value of attribute max_left_offset.



34
35
36
# File 'lib/applitools/core/floating_region.rb', line 34

def max_left_offset
  @max_left_offset
end

#max_right_offsetObject

Returns the value of attribute max_right_offset.



34
35
36
# File 'lib/applitools/core/floating_region.rb', line 34

def max_right_offset
  @max_right_offset
end

#max_top_offsetObject

Returns the value of attribute max_top_offset.



34
35
36
# File 'lib/applitools/core/floating_region.rb', line 34

def max_top_offset
  @max_top_offset
end

Class Method Details

.any(element, *args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/applitools/core/floating_region.rb', line 5

def any(element, *args)
  case element
  when Applitools::Region
    for_element(element, *args)
  when ::Selenium::WebDriver::Element
    for_element(Applitools::Region.from_location_size(element.location, element.size), *args)
  when Applitools::Selenium::Element
    for_element(element.bounds, *args)
  else
    raise Applitools::EyesIllegalArgument.new "Unsupported element - #{element.class}"
  end
end

.for_element(element, *args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/applitools/core/floating_region.rb', line 18

def for_element(element, *args)
  case args.count
  when 1
    new element, args.first
  when 4
    new element, FloatingBounds.new(*args)
  else
    raise(
      Applitools::EyesIllegalArgument,
      'Applitools::FloatingRegion.for_element has been called with illegal argument'
    )
  end
end

Instance Method Details

#scale_it!(scale_factor) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/applitools/core/floating_region.rb', line 72

def scale_it!(scale_factor)
  self.left *= scale_factor
  self.top *= scale_factor
  self.width *= scale_factor
  self.height *= scale_factor
  self.max_left_offset *= scale_factor
  self.max_top_offset *= scale_factor
  self.max_right_offset *= scale_factor
  self.max_bottom_offset *= scale_factor
  self
end

#to_hashObject



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/applitools/core/floating_region.rb', line 84

def to_hash
  {
    'Top' => top,
    'Left' => left,
    'Width' => width,
    'Height' => height,
    'MaxUpOffset' => max_top_offset + padding_top,
    'MaxLeftOffset' => max_left_offset + padding_left,
    'MaxRightOffset' => max_right_offset + padding_right,
    'MaxDownOffset' => max_bottom_offset + padding_bottom
  }
end