lib/capybara/screenshot/diff/region.rb in capybara-screenshot-diff-1.8.3 vs lib/capybara/screenshot/diff/region.rb in capybara-screenshot-diff-1.9.0
- old
+ new
@@ -5,17 +5,10 @@
def initialize(x, y, width, height)
@x, @y, @width, @height = x, y, width, height
end
- def self.from_top_left_corner_coordinates(x, y, width, height)
- return nil unless x && y && width && height
- return nil if width < 0 || height < 0
-
- Region.new(x, y, width, height)
- end
-
def self.from_edge_coordinates(left, top, right, bottom)
return nil unless left && top && right && bottom
return nil if right < left || bottom < top
Region.new(left, top, right - left, bottom - top)
@@ -80,7 +73,35 @@
intersect.move_by(-x, -y)
end
def cover?(x, y)
left <= x && x <= right && top <= y && y <= bottom
+ end
+
+ def empty?
+ width.zero? || height.zero?
+ end
+
+ def blank?
+ empty?
+ end
+
+ def present?
+ !empty?
+ end
+
+ def inspect
+ "Region(x: #{x}, y: #{y}, width: #{width}, height: #{height})"
+ end
+
+ # need to add this method to make it work with assert_equal
+ def ==(other)
+ case other
+ when Region
+ x == other.x && y == other.y && width == other.width && height == other.height
+ when Array
+ to_a == other
+ else
+ false
+ end
end
end