Class: Applitools::RectangleSize

Inherits:
Struct
  • Object
show all
Includes:
HashExtension
Defined in:
lib/applitools/core/rectangle_size.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HashExtension

#struct_define_to_h_method

Constructor Details

#initialize(*args) ⇒ RectangleSize

Returns a new instance of RectangleSize.



30
31
32
33
# File 'lib/applitools/core/rectangle_size.rb', line 30

def initialize(*args)
  super
  struct_define_to_h_method if respond_to? :struct_define_to_h_method
end

Instance Attribute Details

#heightObject

Returns the value of attribute height

Returns:

  • (Object)

    the current value of height



3
4
5
# File 'lib/applitools/core/rectangle_size.rb', line 3

def height
  @height
end

#widthObject

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



3
4
5
# File 'lib/applitools/core/rectangle_size.rb', line 3

def width
  @width
end

Class Method Details

.from_any_argument(value) ⇒ Object Also known as: for



6
7
8
9
10
11
12
# File 'lib/applitools/core/rectangle_size.rb', line 6

def from_any_argument(value)
  return from_string(value) if value.is_a? String
  return from_hash(value) if value.is_a? Hash
  return from_struct(value) if value.respond_to?(:width) & value.respond_to?(:height)
  return value if value.is_a? self
  nil
end

.from_hash(value) ⇒ Object



21
22
23
# File 'lib/applitools/core/rectangle_size.rb', line 21

def from_hash(value)
  new value[:width].to_i, value[:height].to_i
end

.from_string(value) ⇒ Object



16
17
18
19
# File 'lib/applitools/core/rectangle_size.rb', line 16

def from_string(value)
  width, height = value.split(/x/)
  new width.to_i, height.to_i
end

.from_struct(value) ⇒ Object



25
26
27
# File 'lib/applitools/core/rectangle_size.rb', line 25

def from_struct(value)
  new value.width, value.height
end

Instance Method Details

#+(other) ⇒ Object



45
46
47
48
49
# File 'lib/applitools/core/rectangle_size.rb', line 45

def +(other)
  self.width = width + other.width
  self.height = height + other.height
  self
end

#-(other) ⇒ Object



39
40
41
42
43
# File 'lib/applitools/core/rectangle_size.rb', line 39

def -(other)
  self.width = width - other.width
  self.height = height - other.height
  self
end

#scale_it!(scale_factor) ⇒ Object



51
52
53
54
55
# File 'lib/applitools/core/rectangle_size.rb', line 51

def scale_it!(scale_factor)
  self.width *= scale_factor
  self.height *= scale_factor
  self
end

#to_hashObject



57
58
59
# File 'lib/applitools/core/rectangle_size.rb', line 57

def to_hash
  to_h
end

#to_sObject



35
36
37
# File 'lib/applitools/core/rectangle_size.rb', line 35

def to_s
  "#{width}x#{height}"
end