Class: Plato
Overview
Hereda de la clase Plato_i y añade la emisión de gases de efecto invernadero y el uso de terreno
Direct Known Subclasses
Instance Attribute Summary collapse
-
#emision_ ⇒ Object
Returns the value of attribute emision_.
-
#terreno_ ⇒ Object
Returns the value of attribute terreno_.
Attributes inherited from Plato_i
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Módulo comparable.
-
#emision_total ⇒ Object
Emision de gases de efecto invernadero.
-
#energia(x) ⇒ Object
Devuelve el índice de energía.
-
#huella_carbono(x) ⇒ Object
Devuelve el índice de huella de carbono.
-
#huella_nutricional ⇒ Object
Devuelve la huella nutricional.
-
#impacto ⇒ Object
Devuelve el impacto ambiental.
-
#initalize(string, alimentos, peso) ⇒ Object
Constructor clase Plato.
-
#terreno_total ⇒ Object
Uso de terreno total en m2.
Methods inherited from Plato_i
#initialize, #porc_carbo, #porc_lipidos, #porc_proteinas, #vct
Constructor Details
This class inherits a constructor from Plato_i
Instance Attribute Details
#emision_ ⇒ Object
Returns the value of attribute emision_.
80 81 82 |
# File 'lib/p6/plato.rb', line 80 def emision_ @emision_ end |
#terreno_ ⇒ Object
Returns the value of attribute terreno_.
80 81 82 |
# File 'lib/p6/plato.rb', line 80 def terreno_ @terreno_ end |
Instance Method Details
#<=>(other) ⇒ Object
Módulo comparable
150 151 152 |
# File 'lib/p6/plato.rb', line 150 def <=>(other) huella_nutricional <=> other.huella_nutricional end |
#emision_total ⇒ Object
Emision de gases de efecto invernadero
90 91 92 93 94 95 96 97 98 |
# File 'lib/p6/plato.rb', line 90 def emision_total total = 0 total = @alimentos_.zip(peso_).collect{|alimento, peso| (peso * alimento.emision_) / 100 }.reduce(:+) return total end |
#energia(x) ⇒ Object
Devuelve el índice de energía
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/p6/plato.rb', line 117 def energia(x) if x < 670 return 1 elsif x >= 670 && x<= 830 return 2 else return 3 end end |
#huella_carbono(x) ⇒ Object
Devuelve el índice de huella de carbono
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/p6/plato.rb', line 131 def huella_carbono(x) if x < 800 return 1 elsif x >= 800 && x <= 1200 return 2 else return 3 end end |
#huella_nutricional ⇒ Object
Devuelve la huella nutricional
145 146 147 |
# File 'lib/p6/plato.rb', line 145 def huella_nutricional return (energia(vct) + huella_carbono(emision_total)) / 2 end |
#impacto ⇒ Object
Devuelve el impacto ambiental
112 113 114 |
# File 'lib/p6/plato.rb', line 112 def impacto return emision_ + terreno_ end |
#initalize(string, alimentos, peso) ⇒ Object
Constructor clase Plato
83 84 85 86 87 |
# File 'lib/p6/plato.rb', line 83 def initalize(string, alimentos, peso) super(string, alimentos, peso) @emision_ = emision_total @terreno_ = terreno_total end |
#terreno_total ⇒ Object
Uso de terreno total en m2
101 102 103 104 105 106 107 108 109 |
# File 'lib/p6/plato.rb', line 101 def terreno_total total = 0 total = @alimentos_.zip(peso_).collect{|alimento, peso| (peso * alimento.terreno_) / 100 }.reduce(:+) return total end |