Class: Pulo::Cuboid
- Inherits:
-
Object
- Object
- Pulo::Cuboid
- Includes:
- Figure3D
- Defined in:
- lib/pulo/figure/figure3d.rb
Instance Attribute Summary collapse
-
#faces ⇒ Object
readonly
Returns the value of attribute faces.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Attributes included from Figure3D
Instance Method Summary collapse
-
#initialize(width: nil, height: nil, length: nil, volume: nil, face: nil) ⇒ Cuboid
constructor
A new instance of Cuboid.
Methods included from Quantity_Checker
Constructor Details
#initialize(width: nil, height: nil, length: nil, volume: nil, face: nil) ⇒ Cuboid
Returns a new instance of Cuboid.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pulo/figure/figure3d.rb', line 61 def initialize(width: nil, height: nil, length: nil, volume: nil, face: nil) raise 'Cuboid needs width, length and height or volume and face or length and face.' unless ((width && length && height) || (volume && face) || (length && face)) @faces=[] if width and length and height @width=width; @length=length; @height=height @faces[0]=Rectangle.new(width: width, height: height) @faces[1]=Rectangle.new(width: width, height: length) @faces[2]=Rectangle.new(width: length, height: height) @volume=@faces[0].area*@length end if volume and face @volume=volume @faces[0]=face @width=@faces[0].width @height=@faces[0].height @length=@volume/@faces[0].area @faces[1]=Rectangle.new(width: @width, height: @length) @faces[2]=Rectangle.new(width: @length, height: @height) end if face and length @faces[0]=face @length=length @volume=face.area * length @width=@faces[0].width @height=@faces[0].height @faces[1]=Rectangle.new(width: @width, height: @length) @faces[2]=Rectangle.new(width: @length, height: @height) end @surfacearea=(@faces[0].area+@faces[1].area+@faces[2].area)*2 end |
Instance Attribute Details
#faces ⇒ Object (readonly)
Returns the value of attribute faces.
60 61 62 |
# File 'lib/pulo/figure/figure3d.rb', line 60 def faces @faces end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
60 61 62 |
# File 'lib/pulo/figure/figure3d.rb', line 60 def height @height end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
60 61 62 |
# File 'lib/pulo/figure/figure3d.rb', line 60 def length @length end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
60 61 62 |
# File 'lib/pulo/figure/figure3d.rb', line 60 def width @width end |