Class: Pulo::Rectangle

Inherits:
Object
  • Object
show all
Includes:
Figure2D
Defined in:
lib/pulo/figure/figure2d.rb

Instance Attribute Summary collapse

Attributes included from Figure2D

#area, #perimeter

Instance Method Summary collapse

Methods included from Figure2D

#*

Methods included from Quantity_Checker

#quantity_check

Constructor Details

#initialize(area: nil, width: nil, height: nil) ⇒ Rectangle

Returns a new instance of Rectangle.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/pulo/figure/figure2d.rb', line 69

def initialize(area: nil, width: nil, height: nil)
  quantity_check [area,Area] ,[width,Length] , [height,Length]
  raise 'Rectangle needs width and height or area and width or height.' unless (width && height) || (area && (width || height))
  if area
    @area=area
    if width
      @width=width; @height=@area/@width
    else
      @height=height; @width=@area/@height
    end
  else
    @width=width; @height=height
    @area=@width*@height
  end
  @perimeter=@width*2+@height*2
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



64
65
66
# File 'lib/pulo/figure/figure2d.rb', line 64

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



64
65
66
# File 'lib/pulo/figure/figure2d.rb', line 64

def width
  @width
end

Instance Method Details

#extrusion_figureObject



66
67
68
# File 'lib/pulo/figure/figure2d.rb', line 66

def extrusion_figure
  Cuboid
end