Class: Pulo::Cube

Inherits:
Object
  • Object
show all
Includes:
Figure3D
Defined in:
lib/pulo/figure/figure3d.rb

Instance Attribute Summary collapse

Attributes included from Figure3D

#surfacearea, #volume

Instance Method Summary collapse

Methods included from Quantity_Checker

#quantity_check

Constructor Details

#initialize(length: nil, face: nil, volume: nil) ⇒ Cube

Returns a new instance of Cube.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pulo/figure/figure3d.rb', line 37

def initialize(length: nil, face: nil, volume: nil)
  quantity_check [length,Length] ,[face,Square], [volume, Volume]
  raise 'Cube needs volume or face or length.' unless (length || volume || face)

  if volume
    @volume=volume
    @length=volume.rt(3)
    @face=Square.new(width: @length)
  elsif face
    @face=face
    @length=@face.width
    @volume=@face.area*@length
  elsif length
    @length=length
    @face=Square.new(width: @length)
    @volume=@face.area*@length
  end
  @surfacearea=@face.area*6
end

Instance Attribute Details

#faceObject (readonly)

Returns the value of attribute face.



35
36
37
# File 'lib/pulo/figure/figure3d.rb', line 35

def face
  @face
end

#lengthObject (readonly)

Returns the value of attribute length.



35
36
37
# File 'lib/pulo/figure/figure3d.rb', line 35

def length
  @length
end