Class: Alimento

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

Overview

Esta clase permite representar la información básica de un alimento dado, sus proteinas, glúcidos y lípidos además, calcula el índice calórico del mismo.

Author

Alberto González (alu0100949568@ull.edu.es)

Copyright

Cretive Commons

License

Distributes under the same terms as Ruby

Direct Known Subclasses

Alimento_concreto

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nom, prot, gluc, lip) ⇒ Alimento

Se asigna el nombre y la información nutricional del alimento



12
13
14
15
16
17
18
# File 'lib/P06/alimento.rb', line 12

def initialize(nom, prot, gluc, lip)
	@nom = nom
	@prot = prot
	@gluc = gluc
	@lip = lip
	@cal_index = (@prot.to_f*4 + @gluc.to_f*4 + @lip.to_f*9).round(2)
end

Instance Attribute Details

#cal_indexObject (readonly)

Returns the value of attribute cal_index



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

def cal_index
  @cal_index
end

#glucObject (readonly)

Returns the value of attribute gluc



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

def gluc
  @gluc
end

#lipObject (readonly)

Returns the value of attribute lip



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

def lip
  @lip
end

#nomObject (readonly)

Returns the value of attribute nom



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

def nom
  @nom
end

#protObject (readonly)

Returns the value of attribute prot



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

def prot
  @prot
end

Instance Method Details

#to_sObject

Muestra la información de un alimento en concreto



21
22
23
24
# File 'lib/P06/alimento.rb', line 21

def to_s
	#El huevo frito tiene 14.1 proteinas, 0.0 glúcidos, 19.5 lípidos
	" #{@nom}: #{@prot} proteinas, #{@gluc} glúcidos, #{@lip} lípidos, #{@cal_index} calorías"
end