Class: Alimentos
- Inherits:
-
Object
- Object
- Alimentos
- Includes:
- Comparable
- Defined in:
- lib/alimentacion/alimentos.rb
Overview
Esta clase contiene información sobre alimentos, tales como las proteínas, lípidos, hidratos,etc. Se calcula el valor energético de cada alimento, así como su impacto ambiental en hombres y mujeres.
- Author
-
David Hernández Suárez (david@alimentos)
- Copyright
-
Cretive Commons
- License
-
Distributes under the same terms as Ruby
Instance Attribute Summary collapse
-
#gei ⇒ Object
Returns the value of attribute gei.
-
#hidratos ⇒ Object
Returns the value of attribute hidratos.
-
#lipidos ⇒ Object
Returns the value of attribute lipidos.
-
#nombre ⇒ Object
Returns the value of attribute nombre.
-
#proteinas ⇒ Object
Returns the value of attribute proteinas.
-
#terreno ⇒ Object
Returns the value of attribute terreno.
Instance Method Summary collapse
-
#<=>(anOther) ⇒ Object
Se utiliza el módulo Comparable, comparando los alimentos en base a sus proteínas.
-
#auxiliar(gramos) ⇒ Object
Función auxiliar para calcular los gases anuales.
-
#auxiliar2(gramos) ⇒ Object
Función auxiliar para calcular el uso del terreno anual.
-
#impacto_hombre(gramos) ⇒ Object
Se calcula el impacto ambiental de un alimento en un hombre.
-
#impacto_mujer(gramos1, gramos2, gramos3, gramos4, gramos5) ⇒ Object
Se calcula el impacto ambiental de un alimento en una mujer.
-
#initialize(nombre, proteinas, hidratos, lipidos, gei, terreno) ⇒ Alimentos
constructor
Se asignan el nombre del alimento, sus proteínas, hidratos, lípidos, gases y uso del terreno.
-
#to_s ⇒ Object
Se obtiene el alimento formateado.
-
#valor_energetico ⇒ Object
Se calcula el valor energético (calórico) del alimento.
Constructor Details
#initialize(nombre, proteinas, hidratos, lipidos, gei, terreno) ⇒ Alimentos
Se asignan el nombre del alimento, sus proteínas, hidratos, lípidos, gases y uso del terreno.
19 20 21 |
# File 'lib/alimentacion/alimentos.rb', line 19 def initialize(nombre,proteinas,hidratos,lipidos,gei,terreno) @nombre,@proteinas,@hidratos,@lipidos,@gei,@terreno = nombre,proteinas,hidratos,lipidos,gei,terreno end |
Instance Attribute Details
#gei ⇒ Object
Returns the value of attribute gei.
10 11 12 |
# File 'lib/alimentacion/alimentos.rb', line 10 def gei @gei end |
#hidratos ⇒ Object
Returns the value of attribute hidratos.
10 11 12 |
# File 'lib/alimentacion/alimentos.rb', line 10 def hidratos @hidratos end |
#lipidos ⇒ Object
Returns the value of attribute lipidos.
10 11 12 |
# File 'lib/alimentacion/alimentos.rb', line 10 def lipidos @lipidos end |
#nombre ⇒ Object
Returns the value of attribute nombre.
10 11 12 |
# File 'lib/alimentacion/alimentos.rb', line 10 def nombre @nombre end |
#proteinas ⇒ Object
Returns the value of attribute proteinas.
10 11 12 |
# File 'lib/alimentacion/alimentos.rb', line 10 def proteinas @proteinas end |
#terreno ⇒ Object
Returns the value of attribute terreno.
10 11 12 |
# File 'lib/alimentacion/alimentos.rb', line 10 def terreno @terreno end |
Instance Method Details
#<=>(anOther) ⇒ Object
Se utiliza el módulo Comparable, comparando los alimentos en base a sus proteínas.
14 15 16 |
# File 'lib/alimentacion/alimentos.rb', line 14 def <=>(anOther) self. proteinas <=> anOther.proteinas end |
#auxiliar(gramos) ⇒ Object
Función auxiliar para calcular los gases anuales.
35 36 37 |
# File 'lib/alimentacion/alimentos.rb', line 35 def auxiliar(gramos) x = ( @gei * gramos ) / 1000 end |
#auxiliar2(gramos) ⇒ Object
Función auxiliar para calcular el uso del terreno anual.
40 41 42 |
# File 'lib/alimentacion/alimentos.rb', line 40 def auxiliar2(gramos) x = ( @terreno * gramos ) / 1000 end |
#impacto_hombre(gramos) ⇒ Object
Se calcula el impacto ambiental de un alimento en un hombre.
45 46 47 48 49 50 51 52 |
# File 'lib/alimentacion/alimentos.rb', line 45 def impacto_hombre(gramos) alimento1 = Alimentos.new("Carne vaca",21.1,0.0,3.1,50.0,164.0) alimento2 = Alimentos.new("Salmon",19.9,0.0,13.6,6.0,3.7) alimento3 = Alimentos.new("Huevos",13.0,1.1,11.0,4.2,5.7) a = alimento1.auxiliar(gramos) + alimento2.auxiliar(gramos) + alimento3.auxiliar(gramos) b = alimento1.auxiliar2(gramos) + alimento2.auxiliar2(gramos) + alimento3.auxiliar2(gramos) vector = [a.round(2),b.round(2)] end |
#impacto_mujer(gramos1, gramos2, gramos3, gramos4, gramos5) ⇒ Object
Se calcula el impacto ambiental de un alimento en una mujer.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/alimentacion/alimentos.rb', line 55 def impacto_mujer(gramos1,gramos2,gramos3,gramos4,gramos5) alimento1 = Alimentos.new("Tofu",10,2.37,6,2.0,2.2) alimento2 = Alimentos.new("Nuez",50,10.5,27,0.3,7.9) alimento3 = Alimentos.new("Camarones",10,0.85,0.34,18.0,2.0) alimento4 = Alimentos.new("Chocolate",5,44.34,28.30,2.3,3.4) alimento5 = Alimentos.new("Leche",6,8.72,5.82,3.2,8.9) a = alimento1.auxiliar(gramos1) + alimento2.auxiliar(gramos2) + alimento3.auxiliar(gramos3) + alimento4.auxiliar(gramos4) + alimento5.auxiliar(gramos5) b = alimento1.auxiliar2(gramos1) + alimento2.auxiliar2(gramos2) + alimento3.auxiliar2(gramos3) + alimento4.auxiliar2(gramos4) + alimento5.auxiliar2(gramos5) vector = [a.round(2),b.round(2)] end |
#to_s ⇒ Object
Se obtiene el alimento formateado.
24 25 26 |
# File 'lib/alimentacion/alimentos.rb', line 24 def to_s "(#{@nombre},#{@proteinas},#{@hidratos},#{@lipidos},#{@gei},#{@terreno})" end |
#valor_energetico ⇒ Object
Se calcula el valor energético (calórico) del alimento.
29 30 31 32 |
# File 'lib/alimentacion/alimentos.rb', line 29 def valor_energetico energia = 4 * (@proteinas + @hidratos) + (@lipidos * 9) energia.round(2) end |