Class: Alimento
Overview
Clase alimento, contiene toda la información para describir un alimento
Instance Attribute Summary collapse
-
#carbohidratos ⇒ Object
readonly
devuelve la cantidad de carbohidratos del alimento.
-
#gases ⇒ Object
readonly
devuelve las emisiones de gases diarias de un alimento.
-
#lipidos ⇒ Object
readonly
devuelve la cantidad de lipidos contenidos del alimento.
-
#nombre ⇒ Object
readonly
devuelve el nombre del alimento.
-
#proteinas ⇒ Object
readonly
devuelve la cantidad de proteinas contenidos del alimento.
-
#terreno ⇒ Object
readonly
devuelve el terreno necesario para cultivar el alimento.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #impac_ambien(array) ⇒ Object
-
#initialize(n, pro, ch, l, g, te) ⇒ Alimento
constructor
Crea un alimento tras pasarle una serie de parámetros.
-
#to_string ⇒ Object
Devuelve cada uno de los parámetros de Alimento como una string.
-
#val_ener ⇒ Object
Calcula el valor energético del alimento.
Constructor Details
#initialize(n, pro, ch, l, g, te) ⇒ Alimento
Crea un alimento tras pasarle una serie de parámetros
13 14 15 16 17 18 19 20 |
# File 'lib/p6/p6.rb', line 13 def initialize(n , pro , ch , l , g , te) @nombre= n @proteinas= pro @carbohidratos= ch @lipidos= l @gases= g @terreno = te end |
Instance Attribute Details
#carbohidratos ⇒ Object (readonly)
devuelve la cantidad de carbohidratos del alimento
9 10 11 |
# File 'lib/p6/p6.rb', line 9 def carbohidratos @carbohidratos end |
#gases ⇒ Object (readonly)
devuelve las emisiones de gases diarias de un alimento
9 10 11 |
# File 'lib/p6/p6.rb', line 9 def gases @gases end |
#lipidos ⇒ Object (readonly)
devuelve la cantidad de lipidos contenidos del alimento
9 10 11 |
# File 'lib/p6/p6.rb', line 9 def lipidos @lipidos end |
#nombre ⇒ Object (readonly)
devuelve el nombre del alimento
9 10 11 |
# File 'lib/p6/p6.rb', line 9 def nombre @nombre end |
#proteinas ⇒ Object (readonly)
devuelve la cantidad de proteinas contenidos del alimento
9 10 11 |
# File 'lib/p6/p6.rb', line 9 def proteinas @proteinas end |
#terreno ⇒ Object (readonly)
devuelve el terreno necesario para cultivar el alimento
9 10 11 |
# File 'lib/p6/p6.rb', line 9 def terreno @terreno end |
Instance Method Details
#<=>(other) ⇒ Object
46 47 48 |
# File 'lib/p6/p6.rb', line 46 def <=>(other) val_ener <=> other.val_ener end |
#impac_ambien(array) ⇒ Object
40 41 42 43 44 |
# File 'lib/p6/p6.rb', line 40 def impac_ambien array total = 0 total = array.sum { |array| array.gases + array.terreno } return total end |
#to_string ⇒ Object
Devuelve cada uno de los parámetros de Alimento como una string
25 26 27 |
# File 'lib/p6/p6.rb', line 25 def to_string() "Nombre: #{@nombre} \n Proteínas: #{@proteinas} \n Carbohidratos: #{@carbohidratos} \n Lípidos: #{@lipidos} \n Gases de efecto invernadero: #{@gases} \n Terreno: #{@terreno} \n" end |
#val_ener ⇒ Object
Calcula el valor energético del alimento
31 32 33 34 35 36 37 |
# File 'lib/p6/p6.rb', line 31 def val_ener kcal_ch = @carbohidratos*4 kcal_lip = @lipidos*9 kcal_pro = @proteinas*4 return (kcal_ch + kcal_lip + kcal_pro) end |