Class: IMC

Inherits:
Object
  • Object
show all
Defined in:
lib/imc.rb

Overview

Clase con datos nutricionales

Direct Known Subclasses

Individuo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a, b, c, d) ⇒ IMC

Constructor de un imc

Parameters:

  • a (Number)

    peso del paciente

  • b (Number)

    altura del paciente

  • c (Number)

    edad del paciente

  • d (1, 0)

    sexo del paciente



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

#aNumber (readonly)

peso del paciente

Returns:

  • (Number)

    the current value of a



8
9
10
# File 'lib/imc.rb', line 8

def a
  @a
end

#alturaObject (readonly)

Returns the value of attribute altura.



9
10
11
# File 'lib/imc.rb', line 9

def altura
  @altura
end

#bNumber (readonly)

altura del paciente

Returns:

  • (Number)

    the current value of b



8
9
10
# File 'lib/imc.rb', line 8

def b
  @b
end

#cNumber (readonly)

edad del paciente

Returns:

  • (Number)

    the current value of c



8
9
10
# File 'lib/imc.rb', line 8

def c
  @c
end

#d1, 0 (readonly)

sexo del paciente

Returns:

  • (1, 0)

    the current value of d



8
9
10
# File 'lib/imc.rb', line 8

def d
  @d
end

#edadObject (readonly)

Returns the value of attribute edad.



9
10
11
# File 'lib/imc.rb', line 9

def edad
  @edad
end

#pesoObject (readonly)

Returns the value of attribute peso.



9
10
11
# File 'lib/imc.rb', line 9

def peso
  @peso
end

#sexoObject (readonly)

Returns the value of attribute sexo.



9
10
11
# File 'lib/imc.rb', line 9

def sexo
  @sexo
end

Instance Method Details

#calcular_imcObject

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_grasoObject

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_sString

Convierte el objeto a una cadena de caracteres

Returns:

  • (String)

    devuelve el imc como un string



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