Class: Applitools::DynamicRegion

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

Constant Summary

Constants inherited from Region

Region::DEFAULT_SUBREGIONS_INTERSECTION, Region::EMPTY

Instance Attribute Summary collapse

Attributes inherited from Region

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

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, #scale_it!, #size, #size_equals?, #sub_regions, sub_regions_with_fixed_size, sub_regions_with_varying_size, #to_s, #with_padding

Constructor Details

#initialize(element, region_type) ⇒ DynamicRegion

Returns a new instance of DynamicRegion.



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

def initialize(element, region_type)
  if element.is_a?(::Applitools::Region)
    super(element.left, element.top, element.width, element.height)
    self.padding = element.current_padding if element.current_padding
  else
    super(element.location.x, element.location.y, element.size.width, element.size.height)
  end
  self.region_type = region_type
end

Instance Attribute Details

#region_typeObject

Returns the value of attribute region_type.



7
8
9
# File 'lib/applitools/core/dynamic_region.rb', line 7

def region_type
  @region_type
end

Instance Method Details

#==(other) ⇒ Object



53
54
55
# File 'lib/applitools/core/dynamic_region.rb', line 53

def ==(other)
  super && region_type == other.region_type
end

#to_hashObject Also known as: json_data



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/applitools/core/dynamic_region.rb', line 18

def to_hash
  hash = {
    region: {
      x: left,
      y: top,
      width: width,
      height: height
    }
  }
  
  # Type should always be an array
  if region_type
    hash[:type] = region_type.is_a?(Array) ? region_type : [region_type]
  end
  
  if current_padding && !current_padding.zero?
    if padding_top == padding_right && padding_right == padding_bottom && padding_bottom == padding_left
      # If all padding values are the same, use a single number
      hash[:padding] = padding_top
    else
      # Otherwise, use an object with individual values
      hash[:padding] = {
        top: padding_top,
        right: padding_right,
        bottom: padding_bottom,
        left: padding_left
      }
    end
  end
  
  hash
end