Class: Pulo::Cylinder

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(face: nil, length: nil, volume: nil, radius: nil, diameter: nil) ⇒ Cylinder

Returns a new instance of Cylinder.



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/pulo/figure/figure3d.rb', line 98

def initialize (face: nil, length: nil, volume: nil, radius: nil, diameter: nil)
  quantity_check [face,Circle] ,[length,Length] , [volume,Volume], [radius, Length], [diameter, Length]
  raise 'Cylinder needs length and face or volume and length or volume and radius or diameter.' unless
      (face && length) || (volume && length) || (volume && (radius || diameter)) || (length && (radius || diameter))

  if face and length
    @face=face
    @length=length
    @volume=@face.area*@length
  else
    if volume and length
      @length=length
      @volume=volume
      @face=Circle.new(area: @volume/@length)
    else
      if (radius or diameter) and volume
        @face=Circle.new(radius: radius, diameter: diameter)
        @volume=volume
        @length=volume/@face.area
      else
        @face=Circle.new(radius: radius, diameter: diameter)
        @length=length
        @volume=@face.area*@length
      end
    end
  end

  @surfacearea=@face.area*2+@face.perimeter*@length
  @area=@face.area
  @radius=@face.radius
end

Instance Attribute Details

#faceObject (readonly)

Returns the value of attribute face.



97
98
99
# File 'lib/pulo/figure/figure3d.rb', line 97

def face
  @face
end

#lengthObject (readonly)

Returns the value of attribute length.



97
98
99
# File 'lib/pulo/figure/figure3d.rb', line 97

def length
  @length
end