Class: BracketNotation::Geometry::Size
- Inherits:
-
Object
- Object
- BracketNotation::Geometry::Size
- 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
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#==(rvalue) ⇒ Object
Test to see of two sizes are equal, where equality is defined as having identical widths and heights.
-
#initialize(width = 0, height = 0) ⇒ Size
constructor
A new instance of Size.
- #inspect ⇒ Object (also: #to_s)
-
#size_by_adding_to_height(delta_height) ⇒ Object
Create a new size by adding the given amount to the current size’s height.
-
#size_by_adding_to_width(delta_width) ⇒ Object
Create a new size by adding the given amount to the current size’s width.
-
#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.
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
#height ⇒ Object (readonly)
Returns the value of attribute height.
33 34 35 |
# File 'lib/bracket_notation/geometry/size.rb', line 33 def height @height end |
#width ⇒ Object (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 |
#inspect ⇒ Object 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 |