Class: IMC
- Inherits:
-
Object
- Object
- IMC
- Defined in:
- lib/imc.rb
Overview
Clase con datos nutricionales
Direct Known Subclasses
Instance Attribute Summary collapse
-
#a ⇒ Number
readonly
peso del paciente.
-
#altura ⇒ Object
readonly
Returns the value of attribute altura.
-
#b ⇒ Number
readonly
altura del paciente.
-
#c ⇒ Number
readonly
edad del paciente.
-
#d ⇒ 1, 0
readonly
sexo del paciente.
-
#edad ⇒ Object
readonly
Returns the value of attribute edad.
-
#peso ⇒ Object
readonly
Returns the value of attribute peso.
-
#sexo ⇒ Object
readonly
Returns the value of attribute sexo.
Instance Method Summary collapse
-
#calcular_imc ⇒ Object
Calcula el imc de un individuo.
-
#initialize(a, b, c, d) ⇒ IMC
constructor
Constructor de un imc.
-
#porcentaje_graso ⇒ Object
Calcula el %graso.
-
#to_s ⇒ String
Convierte el objeto a una cadena de caracteres.
Constructor Details
#initialize(a, b, c, d) ⇒ IMC
Constructor de un imc
19 20 21 22 23 24 |
# File 'lib/imc.rb', line 19 def initialize(a,b,c,d) @peso = a @altura = b @edad = c @sexo = d end |
Instance Attribute Details
#a ⇒ Number (readonly)
peso del paciente
8 9 10 |
# File 'lib/imc.rb', line 8 def a @a end |
#altura ⇒ Object (readonly)
Returns the value of attribute altura.
9 10 11 |
# File 'lib/imc.rb', line 9 def altura @altura end |
#b ⇒ Number (readonly)
altura del paciente
8 9 10 |
# File 'lib/imc.rb', line 8 def b @b end |
#c ⇒ Number (readonly)
edad del paciente
8 9 10 |
# File 'lib/imc.rb', line 8 def c @c end |
#d ⇒ 1, 0 (readonly)
sexo del paciente
8 9 10 |
# File 'lib/imc.rb', line 8 def d @d end |
#edad ⇒ Object (readonly)
Returns the value of attribute edad.
9 10 11 |
# File 'lib/imc.rb', line 9 def edad @edad end |
#peso ⇒ Object (readonly)
Returns the value of attribute peso.
9 10 11 |
# File 'lib/imc.rb', line 9 def peso @peso end |
#sexo ⇒ Object (readonly)
Returns the value of attribute sexo.
9 10 11 |
# File 'lib/imc.rb', line 9 def sexo @sexo end |
Instance Method Details
#calcular_imc ⇒ Object
Calcula el imc de un individuo
return [Number] imc
28 29 30 |
# File 'lib/imc.rb', line 28 def calcular_imc (@peso)/(@altura*@altura) end |
#porcentaje_graso ⇒ Object
Calcula el %graso
return [Number] %graso
34 35 36 |
# File 'lib/imc.rb', line 34 def porcentaje_graso (1.2*calcular_imc)+(0.23*@edad)-(10.8*@sexo)-5.4 end |
#to_s ⇒ String
Convierte el objeto a una cadena de caracteres
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/imc.rb', line 40 def to_s rval = "" rval += " pesa #{@peso} kilos , mide #{@altura} metros, tiene #{@edad} aƱos y es" if(sexo == 1) rval+= " un hombre" else rval+= " una mujer" end rval end |