Class: Applitools::Location
- Inherits:
-
Object
- Object
- Applitools::Location
- Defined in:
- lib/applitools/core/location.rb
Constant Summary collapse
- TOP_LEFT =
Location.new(0, 0).freeze
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
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(x, y) ⇒ Location
constructor
A new instance of Location.
- #negative_part ⇒ Object
- #offset(other) ⇒ Object
- #offset_negative(other) ⇒ Object
- #positive_part ⇒ 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.
44 45 46 47 |
# File 'lib/applitools/core/location.rb', line 44 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.
39 40 41 |
# File 'lib/applitools/core/location.rb', line 39 def x @x end |
#y ⇒ Object (readonly) Also known as: top
Returns the value of attribute y.
39 40 41 |
# File 'lib/applitools/core/location.rb', line 39 def y @y end |
Class Method Details
.from_any_attribute(*args) ⇒ Object Also known as: for
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/applitools/core/location.rb', line 7 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
25 26 27 |
# File 'lib/applitools/core/location.rb', line 25 def from_array(value) new value.shift, value.shift end |
.from_hash(value) ⇒ Object
21 22 23 |
# File 'lib/applitools/core/location.rb', line 21 def from_hash(value) new value[:x], value[:y] end |
.from_string(value) ⇒ Object
29 30 31 32 |
# File 'lib/applitools/core/location.rb', line 29 def from_string(value) x, y = value.split(/x/) new x, y end |
.from_struct(value) ⇒ Object
34 35 36 |
# File 'lib/applitools/core/location.rb', line 34 def from_struct(value) new value.x, value.y end |
Instance Method Details
#!=(other) ⇒ Object
60 61 62 |
# File 'lib/applitools/core/location.rb', line 60 def !=(other) !(self == other) end |
#==(other) ⇒ Object Also known as: eql?
55 56 57 58 |
# File 'lib/applitools/core/location.rb', line 55 def ==(other) return super.==(other) unless other.is_a?(Location) @x == other.x && @y == other.y end |
#hash ⇒ Object
66 67 68 |
# File 'lib/applitools/core/location.rb', line 66 def hash @x.hash & @y.hash end |
#negative_part ⇒ Object
70 71 72 73 74 |
# File 'lib/applitools/core/location.rb', line 70 def negative_part new_x = @x < 0 ? @x : 0 new_y = @y < 0 ? @y : 0 self.class.new(new_x.round, new_y.round) end |
#offset(other) ⇒ Object
90 91 92 93 94 |
# File 'lib/applitools/core/location.rb', line 90 def offset(other) @x += other.x @y += other.y self end |
#offset_negative(other) ⇒ Object
96 97 98 99 100 |
# File 'lib/applitools/core/location.rb', line 96 def offset_negative(other) @x -= other.x @y -= other.y self end |
#positive_part ⇒ Object
76 77 78 79 80 |
# File 'lib/applitools/core/location.rb', line 76 def positive_part new_x = @x < 0 ? 0 : @x new_y = @y < 0 ? 0 : @y self.class.new(new_x.round, new_y.round) end |
#scale_it!(scale_factor) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/applitools/core/location.rb', line 102 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
82 83 84 |
# File 'lib/applitools/core/location.rb', line 82 def to_hash( = {}) [:region] ? { left: left, top: top } : { x: x, y: y } end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/applitools/core/location.rb', line 51 def to_s "#{x} x #{y}" end |
#values ⇒ Object
86 87 88 |
# File 'lib/applitools/core/location.rb', line 86 def values [x, y] end |