Class: TestaAppiumDriver::Bounds
- Inherits:
-
Object
- Object
- TestaAppiumDriver::Bounds
- Defined in:
- lib/testa_appium_driver/common/bounds.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
- #offset ⇒ TestaAppiumDriver::Offset readonly
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #ai ⇒ Object
- #as_json ⇒ Object
- #bottom_right ⇒ TestaAppiumDriver::Coordinates
- #center ⇒ TestaAppiumDriver::Coordinates
-
#initialize(top_left, bottom_right, window_width, window_height) ⇒ Bounds
constructor
A new instance of Bounds.
- #to_s ⇒ Object
- #top_left ⇒ TestaAppiumDriver::Coordinates
Constructor Details
#initialize(top_left, bottom_right, window_width, window_height) ⇒ Bounds
Returns a new instance of Bounds.
15 16 17 18 19 20 21 22 |
# File 'lib/testa_appium_driver/common/bounds.rb', line 15 def initialize(top_left, bottom_right, window_width, window_height) @top_left = top_left @bottom_right = bottom_right @width = bottom_right.x - top_left.x @height = bottom_right.y - top_left.y @offset = Offset.new(self, window_width, window_height) @center = TestaAppiumDriver::Coordinates.new(@top_left.x + @width / 2, @top_left.y + @height / 2) end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
8 9 10 |
# File 'lib/testa_appium_driver/common/bounds.rb', line 8 def height @height end |
#offset ⇒ TestaAppiumDriver::Offset (readonly)
35 36 37 |
# File 'lib/testa_appium_driver/common/bounds.rb', line 35 def offset @offset end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
7 8 9 |
# File 'lib/testa_appium_driver/common/bounds.rb', line 7 def width @width end |
Class Method Details
.from_android(bounds, driver) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/testa_appium_driver/common/bounds.rb', line 64 def self.from_android(bounds, driver) matches = bounds.match(/\[(\d+),(\d+)\]\[(\d+),(\d+)\]/) raise "Unexpected bounds: #{bounds}" unless matches captures = matches.captures top_left = Coordinates.new(captures[0], captures[1]) bottom_right = Coordinates.new(captures[2], captures[3]) ws = driver.window_size window_width = ws.width.to_i window_height = ws.height.to_i Bounds.new(top_left, bottom_right, window_width, window_height) end |
.from_ios(rect, driver) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/testa_appium_driver/common/bounds.rb', line 77 def self.from_ios(rect, driver) rect = JSON.parse(rect) top_left = Coordinates.new(rect["x"], rect["y"]) bottom_right = Coordinates.new(top_left.x + rect["width"].to_i, top_left.y + rect["height"].to_i) ws = driver.window_size window_width = ws.width.to_i window_height = ws.height.to_i Bounds.new(top_left, bottom_right, window_width, window_height) end |
Instance Method Details
#ai ⇒ Object
54 55 56 |
# File 'lib/testa_appium_driver/common/bounds.rb', line 54 def ai as_json.ai end |
#as_json ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/testa_appium_driver/common/bounds.rb', line 24 def as_json { width: @width, height: @height, top_left: @top_left.as_json, bottom_right: @bottom_right.as_json, offset: @offset.as_json, } end |
#bottom_right ⇒ TestaAppiumDriver::Coordinates
45 46 47 |
# File 'lib/testa_appium_driver/common/bounds.rb', line 45 def bottom_right @bottom_right end |
#center ⇒ TestaAppiumDriver::Coordinates
50 51 52 |
# File 'lib/testa_appium_driver/common/bounds.rb', line 50 def center @center end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/testa_appium_driver/common/bounds.rb', line 58 def to_s "[#{@top_left.x}, #{@top_left.y}][#{@bottom_right.x}, #{@bottom_right.y}]" end |
#top_left ⇒ TestaAppiumDriver::Coordinates
40 41 42 |
# File 'lib/testa_appium_driver/common/bounds.rb', line 40 def top_left @top_left end |