Class: Roebe::Math::Sphere

Inherits:
Object show all
Defined in:
lib/roebe/math/sphere.rb

Overview

Roebe::Math::Sphere

Instance Method Summary collapse

Constructor Details

#initialize(i = ARGV, run_already = true) ⇒ Sphere

#

initialize

#


23
24
25
26
27
28
29
30
# File 'lib/roebe/math/sphere.rb', line 23

def initialize(
    i           = ARGV,
    run_already = true
  )
  reset
  set_input(i)
  run if run_already
end

Instance Method Details

#calculate_the_surface_area(radius) ⇒ Object Also known as: oberfläche

#

calculate_the_surface_area

Formular for the surface area of a sphere:

4 * PI * (r ** 2)
#


46
47
48
49
# File 'lib/roebe/math/sphere.rb', line 46

def calculate_the_surface_area(radius)
  radius = radius.to_f
  return 4 * PI * (radius ** 2)
end

#calculate_the_volumenObject

#

calculate_the_volumen

This method will calculate the “Kugelvolumen”.

#


107
108
109
110
111
# File 'lib/roebe/math/sphere.rb', line 107

def calculate_the_volumen
  r = @input.to_f # This we assume to be the Radius.
  @volumen = 4.0 / 3 * PI * (r ** 3)
  return @volumen
end

#display_formulas_in_germanObject

#

display_formulas_in_german

#


62
63
64
65
# File 'lib/roebe/math/sphere.rb', line 62

def display_formulas_in_german
  e ('Kugelvolumen V:').ljust(21)+' 4/3 * PI * (r ** 3)'
  e 'Oberfläche der Kugel: 4   * PI * (r ** 2)'
end
#

menu (menu tag)

#


70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/roebe/math/sphere.rb', line 70

def menu(i = @input)
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i # case tag
    # ===================================================================== #
    # === --german
    # ===================================================================== #
    when /^-?-?german/
      display_formulas_in_german
    end
  end
end

#process_the_user_inputObject

#

process_the_user_input

#


95
96
97
98
99
100
# File 'lib/roebe/math/sphere.rb', line 95

def process_the_user_input
  unless @input.nil?
    calculate_the_volumen
    report_result_for_volumen
  end
end

#report_result_for_volumenObject

#

report_result_for_volumen

#


87
88
89
90
# File 'lib/roebe/math/sphere.rb', line 87

def report_result_for_volumen
  opn; e 'A radius of '+simp(@input)+' equals to a Volumen of '+
          sfancy(@volumen.to_f.round(4).to_s)+'.'
end

#resetObject

#

reset (reset tag)

#


35
36
# File 'lib/roebe/math/sphere.rb', line 35

def reset
end

#runObject

#

run (run tag)

#


116
117
118
119
# File 'lib/roebe/math/sphere.rb', line 116

def run
  menu
  process_the_user_input
end

#set_input(i = nil) ⇒ Object

#

set_input

#


54
55
56
57
# File 'lib/roebe/math/sphere.rb', line 54

def set_input(i = nil)
  i = i[0] if i.is_a? Array
  @input = i
end