Class: Applitools::RectangleSize

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

Overview

rubocop:disable Metrics/BlockLength

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.



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

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



6
7
8
# File 'lib/applitools/core/rectangle_size.rb', line 6

def height
  @height
end

#widthObject

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



6
7
8
# File 'lib/applitools/core/rectangle_size.rb', line 6

def width
  @width
end

Class Method Details

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



9
10
11
12
13
14
15
# File 'lib/applitools/core/rectangle_size.rb', line 9

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



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

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

.from_string(value) ⇒ Object



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

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

.from_struct(value) ⇒ Object



28
29
30
# File 'lib/applitools/core/rectangle_size.rb', line 28

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

Instance Method Details

#+(other) ⇒ Object



48
49
50
51
52
# File 'lib/applitools/core/rectangle_size.rb', line 48

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

#-(other) ⇒ Object



42
43
44
45
46
# File 'lib/applitools/core/rectangle_size.rb', line 42

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

#<(other) ⇒ Object



68
69
70
# File 'lib/applitools/core/rectangle_size.rb', line 68

def<(other)
  square < other.square
end

#>(other) ⇒ Object



64
65
66
# File 'lib/applitools/core/rectangle_size.rb', line 64

def >(other)
  square > other.square
end

#scale_it!(scale_factor) ⇒ Object



54
55
56
57
58
# File 'lib/applitools/core/rectangle_size.rb', line 54

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

#squareObject



60
61
62
# File 'lib/applitools/core/rectangle_size.rb', line 60

def square
  width * height
end

#to_hashObject



72
73
74
# File 'lib/applitools/core/rectangle_size.rb', line 72

def to_hash
  to_h
end

#to_sObject



38
39
40
# File 'lib/applitools/core/rectangle_size.rb', line 38

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