Class: IMC

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/NutrientesEdu/IMC.rb,
lib/NutrientesEdu/version.rb

Direct Known Subclasses

Individuos

Constant Summary collapse

VERSION =
"0.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of IMC.



6
7
8
9
10
11
# File 'lib/NutrientesEdu/IMC.rb', line 6

def initialize(a,b,c,d)
	@peso=a
	@altura=b
	@edad=c
	@sexo=d
end

Instance Attribute Details

#alturaObject (readonly)

Returns the value of attribute altura.



4
5
6
# File 'lib/NutrientesEdu/IMC.rb', line 4

def altura
  @altura
end

#edadObject (readonly)

Returns the value of attribute edad.



4
5
6
# File 'lib/NutrientesEdu/IMC.rb', line 4

def edad
  @edad
end

#pesoObject (readonly)

Returns the value of attribute peso.



4
5
6
# File 'lib/NutrientesEdu/IMC.rb', line 4

def peso
  @peso
end

#sexoObject (readonly)

Returns the value of attribute sexo.



4
5
6
# File 'lib/NutrientesEdu/IMC.rb', line 4

def sexo
  @sexo
end

Instance Method Details

#<=>(other) ⇒ Object



25
26
27
# File 'lib/NutrientesEdu/IMC.rb', line 25

def <=> (other)
   calcular_imc <=> other.calcular_imc
end

#calcular_imcObject



13
14
15
# File 'lib/NutrientesEdu/IMC.rb', line 13

def calcular_imc
	(@peso)/(@altura*@altura)
end

#porcentaje_grasaObject



17
18
19
# File 'lib/NutrientesEdu/IMC.rb', line 17

def porcentaje_grasa
	((1.2*calcular_imc)+(0.23*edad)-(10.8*sexo)-5.4)
end

#to_sObject



21
22
23
# File 'lib/NutrientesEdu/IMC.rb', line 21

def to_s
	"#{@peso} #{@altura} #{@edad} #{@sexo}"
end