Class: Applitools::Location
- Inherits:
-
Object
- Object
- Applitools::Location
- Defined in:
- lib/applitools/core/location.rb
Constant Summary collapse
- TOP_LEFT =
Location.new(0, 0)
Instance Attribute Summary collapse
-
#x ⇒ Object
(also: #left)
readonly
Returns the value of attribute x.
-
#y ⇒ Object
(also: #top)
readonly
Returns the value of attribute y.
Class Method Summary collapse
- .from_any_attribute(*args) ⇒ Object (also: for)
- .from_array(value) ⇒ Object
- .from_hash(value) ⇒ Object
- .from_string(value) ⇒ Object
- .from_struct(value) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(x, y) ⇒ Location
constructor
A new instance of Location.
- #offset(other) ⇒ Object
- #offset_negative(other) ⇒ Object
- #scale_it!(scale_factor) ⇒ Object
- #to_hash(options = {}) ⇒ Object
- #to_s ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Location
Returns a new instance of Location.
42 43 44 45 |
# File 'lib/applitools/core/location.rb', line 42 def initialize(x, y) @x = x @y = y end |
Instance Attribute Details
#x ⇒ Object (readonly) Also known as: left
Returns the value of attribute x.
37 38 39 |
# File 'lib/applitools/core/location.rb', line 37 def x @x end |
#y ⇒ Object (readonly) Also known as: top
Returns the value of attribute y.
37 38 39 |
# File 'lib/applitools/core/location.rb', line 37 def y @y end |
Class Method Details
.from_any_attribute(*args) ⇒ Object Also known as: for
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/applitools/core/location.rb', line 5 def from_any_attribute(*args) if args.size == 2 new args[0], args[1] elsif args.size == 1 value = args.shift from_hash(value) if value.is_a? Hash from_array(value) if value.is_a? Array from_string(value) if value.is_a? String from_struct(value) if value.respond_to?(:x) & value.respond_to?(:y) end end |
.from_array(value) ⇒ Object
23 24 25 |
# File 'lib/applitools/core/location.rb', line 23 def from_array(value) new value.shift, value.shift end |
.from_hash(value) ⇒ Object
19 20 21 |
# File 'lib/applitools/core/location.rb', line 19 def from_hash(value) new value[:x], value[:y] end |
.from_string(value) ⇒ Object
27 28 29 30 |
# File 'lib/applitools/core/location.rb', line 27 def from_string(value) x, y = value.split(/x/) new x, y end |
.from_struct(value) ⇒ Object
32 33 34 |
# File 'lib/applitools/core/location.rb', line 32 def from_struct(value) new value.x, value.y end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
53 54 55 56 |
# File 'lib/applitools/core/location.rb', line 53 def ==(other) return super.==(other) unless other.is_a?(Location) @x == other.x && @y == other.y end |
#hash ⇒ Object
60 61 62 |
# File 'lib/applitools/core/location.rb', line 60 def hash @x.hash & @y.hash end |
#offset(other) ⇒ Object
72 73 74 75 76 |
# File 'lib/applitools/core/location.rb', line 72 def offset(other) @x += other.x @y += other.y self end |
#offset_negative(other) ⇒ Object
78 79 80 81 82 |
# File 'lib/applitools/core/location.rb', line 78 def offset_negative(other) @x -= other.x @y -= other.y self end |
#scale_it!(scale_factor) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/applitools/core/location.rb', line 84 def scale_it!(scale_factor) raise Applitools::EyesIllegalArgument, 'scale_factor must be an integer' unless scale_factor.is_a? Integer @x *= scale_factor @y *= scale_factor self end |
#to_hash(options = {}) ⇒ Object
64 65 66 |
# File 'lib/applitools/core/location.rb', line 64 def to_hash( = {}) [:region] ? { left: left, top: top } : { x: x, y: y } end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/applitools/core/location.rb', line 49 def to_s "#{x} x #{y}" end |
#values ⇒ Object
68 69 70 |
# File 'lib/applitools/core/location.rb', line 68 def values [x, y] end |