Class: PlatoDSL
- Inherits:
-
Object
- Object
- PlatoDSL
- Defined in:
- lib/tddAlimentos/platoDSL.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#food ⇒ Object
Returns the value of attribute food.
-
#gei ⇒ Object
Returns the value of attribute gei.
-
#gr ⇒ Object
Returns the value of attribute gr.
-
#name ⇒ Object
Returns the value of attribute name.
-
#terrain ⇒ Object
Returns the value of attribute terrain.
-
#vct ⇒ Object
Returns the value of attribute vct.
Instance Method Summary collapse
- #alimento(options = {}) ⇒ Object
-
#calc_gei ⇒ Object
- Calcula el gas de efecto invernadero que se produce al crear el plato Devuelve
-
GEI del plato.
-
#calc_terrain ⇒ Object
- Calcula el terreno consumido por la producción del plato Devuelve
-
Valor del terreno.
-
#calc_vct ⇒ Object
- Calcula el Valor Calórico Total del plato Devuelve
-
Valor Calórico Total del plato.
- #descripcion(description) ⇒ Object
-
#initialize(name, &block) ⇒ PlatoDSL
constructor
A new instance of PlatoDSL.
- #to_s ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ PlatoDSL
Returns a new instance of PlatoDSL.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tddAlimentos/platoDSL.rb', line 5 def initialize (name, &block) @name = name @description = "" @food = [] @gr = [] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end @vct = calc_vct @gei = calc_gei @terrain = calc_terrain end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/tddAlimentos/platoDSL.rb', line 3 def description @description end |
#food ⇒ Object
Returns the value of attribute food.
3 4 5 |
# File 'lib/tddAlimentos/platoDSL.rb', line 3 def food @food end |
#gei ⇒ Object
Returns the value of attribute gei.
3 4 5 |
# File 'lib/tddAlimentos/platoDSL.rb', line 3 def gei @gei end |
#gr ⇒ Object
Returns the value of attribute gr.
3 4 5 |
# File 'lib/tddAlimentos/platoDSL.rb', line 3 def gr @gr end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/tddAlimentos/platoDSL.rb', line 3 def name @name end |
#terrain ⇒ Object
Returns the value of attribute terrain.
3 4 5 |
# File 'lib/tddAlimentos/platoDSL.rb', line 3 def terrain @terrain end |
#vct ⇒ Object
Returns the value of attribute vct.
3 4 5 |
# File 'lib/tddAlimentos/platoDSL.rb', line 3 def vct @vct end |
Instance Method Details
#alimento(options = {}) ⇒ Object
30 31 32 33 |
# File 'lib/tddAlimentos/platoDSL.rb', line 30 def alimento ( = {}) @food << [:valor] @gr << [:gramos] end |
#calc_gei ⇒ Object
Calcula el gas de efecto invernadero que se produce al crear el plato
- Devuelve
-
GEI del plato
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tddAlimentos/platoDSL.rb', line 69 def calc_gei datos = @food.collect { |x| x.gei } gramos = @gr.collect { |x| x/100.0 } result = 0.0 for i in 0...datos.size result += datos[i] * gramos[i] end result.round(2) end |
#calc_terrain ⇒ Object
Calcula el terreno consumido por la producción del plato
- Devuelve
-
Valor del terreno
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/tddAlimentos/platoDSL.rb', line 83 def calc_terrain datos = @food.collect { |x| x.terrain } gramos = @gr.collect { |x| x/100.0 } result = 0.0 for i in 0...datos.size result += datos[i] * gramos[i] end result end |
#calc_vct ⇒ Object
Calcula el Valor Calórico Total del plato
- Devuelve
-
Valor Calórico Total del plato
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tddAlimentos/platoDSL.rb', line 55 def calc_vct alimentos = @food.collect { |x| x.energetic_value } gramos = @gr.collect { |x| x/100.0 } result = 0.0 for i in 0...alimentos.size result += (gramos[i] * alimentos[i]) end result.round(2) end |
#descripcion(description) ⇒ Object
26 27 28 |
# File 'lib/tddAlimentos/platoDSL.rb', line 26 def descripcion (description) @description = description end |
#to_s ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tddAlimentos/platoDSL.rb', line 35 def to_s str = "" str += @name + "\n" str += @description + "\n" str += "Ingredientes: " @food.each_with_index do |ingredient,index| str += "#{ingredient.name} (#{@gr[index]} gr.)" if index < (@food.size - 1) str += ", " end end str += "\nValor calorico total: " + @vct.to_s + " kcal.\n" str += "Uso de terreno: " + @terrain.to_s + "\n" str += "GEI: " + @gei.to_s end |