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::DEFAULT_SUBREGIONS_INTERSECTION, Region::EMPTY

Instance Attribute Summary collapse

Attributes inherited from Region

#height, #left, #padding, #top, #width

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Region

#[], #bottom, #contains?, #current_padding, #empty?, from_location_size, #intersect, #intersecting?, #location, #location=, #make_empty, #middle_offset, #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.



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
71
72
# File 'lib/applitools/core/floating_region.rb', line 42

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.



36
37
38
# File 'lib/applitools/core/floating_region.rb', line 36

def max_bottom_offset
  @max_bottom_offset
end

#max_left_offsetObject

Returns the value of attribute max_left_offset.



36
37
38
# File 'lib/applitools/core/floating_region.rb', line 36

def max_left_offset
  @max_left_offset
end

#max_right_offsetObject

Returns the value of attribute max_right_offset.



36
37
38
# File 'lib/applitools/core/floating_region.rb', line 36

def max_right_offset
  @max_right_offset
end

#max_top_offsetObject

Returns the value of attribute max_top_offset.



36
37
38
# File 'lib/applitools/core/floating_region.rb', line 36

def max_top_offset
  @max_top_offset
end

Class Method Details

.any(element, *args) ⇒ Object



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

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



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

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

#==(other) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/applitools/core/floating_region.rb', line 86

def ==(other)
  super(other) &&
    max_left_offset == other.max_left_offset &&
    max_top_offset == other.max_top_offset &&
    max_right_offset == other.max_right_offset &&
    max_bottom_offset == other.max_bottom_offset
end

#scale_it!(scale_factor) ⇒ Object



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

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



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/applitools/core/floating_region.rb', line 94

def to_hash
  {
    x: left,
    y: top,
    width: width,
    height: height,
    offset: {
      top: max_top_offset + padding_top,
      bottom: max_bottom_offset + padding_bottom,
      left: max_left_offset + padding_left,
      right: max_right_offset + padding_right
    }
  }
end