Class: BracketNotation::Geometry::Size

Inherits:
Object
  • Object
show all
Defined in:
lib/bracket_notation/geometry/size.rb

Overview

Size represents the size of a rectangle using a width and height field.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width = 0, height = 0) ⇒ Size

Returns a new instance of Size.



35
36
37
38
# File 'lib/bracket_notation/geometry/size.rb', line 35

def initialize(width = 0, height = 0)
  @width = width
  @height = height
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



33
34
35
# File 'lib/bracket_notation/geometry/size.rb', line 33

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



33
34
35
# File 'lib/bracket_notation/geometry/size.rb', line 33

def width
  @width
end

Instance Method Details

#==(rvalue) ⇒ Object

Test to see of two sizes are equal, where equality is defined as having identical widths and heights



42
43
44
# File 'lib/bracket_notation/geometry/size.rb', line 42

def ==(rvalue)
  @width == rvalue.width && @height == rvalue.height
end

#inspectObject Also known as: to_s



62
63
64
# File 'lib/bracket_notation/geometry/size.rb', line 62

def inspect
  "{width: #{@width}, height: #{@height}}"
end

#size_by_adding_to_height(delta_height) ⇒ Object

Create a new size by adding the given amount to the current size’s height



52
53
54
# File 'lib/bracket_notation/geometry/size.rb', line 52

def size_by_adding_to_height(delta_height)
  self.class.new(@width, @height + delta_height)
end

#size_by_adding_to_width(delta_width) ⇒ Object

Create a new size by adding the given amount to the current size’s width



47
48
49
# File 'lib/bracket_notation/geometry/size.rb', line 47

def size_by_adding_to_width(delta_width)
  self.class.new(@width + delta_width, @height)
end

#size_by_adding_to_width_and_height(delta_width, delta_height) ⇒ Object

Create a new size by adding the given amounts to the current size’s width and height



58
59
60
# File 'lib/bracket_notation/geometry/size.rb', line 58

def size_by_adding_to_width_and_height(delta_width, delta_height)
  self.class.new(@width + delta_width, @height + delta_height)
end