Class: Plato_herencia

Inherits:
Plato
  • Object
show all
Includes:
Comparable
Defined in:
lib/pract06/plato_herencia.rb

Overview

Implementacion de la clase heredada Plato_herencia

Instance Attribute Summary collapse

Attributes inherited from Plato

#cantidades_engramos, #cantidades_totales_engramos, #conjunto_alimentos, #nombre_plato

Instance Method Summary collapse

Methods inherited from Plato

#porcentaje_carbohidratos, #porcentaje_lipidos, #porcentaje_proteinas, #valor_calorico_total

Constructor Details

#initialize(nombre_plato, conjunto_alimentos, cantidades_engramos, cantidades_totales_engramos) ⇒ Plato_herencia

Deprecated.

Metodo para inicializar plato heredado

Metodo initialize



13
14
15
16
17
18
19
20
21
# File 'lib/pract06/plato_herencia.rb', line 13

def initialize(nombre_plato, conjunto_alimentos, cantidades_engramos, cantidades_totales_engramos)

  super(nombre_plato, conjunto_alimentos, cantidades_engramos, cantidades_totales_engramos)
  @valor_energetico_plato_alimentos = valor_energetico_plato_alimentos
  @valor = valor
  @total_ve = total_ve
  @huella_nutricional = huella_nutricional

end

Instance Attribute Details

#valor_energetico_plato_alimentosObject (readonly)

Returns the value of attribute valor_energetico_plato_alimentos.



5
6
7
# File 'lib/pract06/plato_herencia.rb', line 5

def valor_energetico_plato_alimentos
  @valor_energetico_plato_alimentos
end

Instance Method Details

#<=>(other) ⇒ Object

Deprecated.

Sirve para comparar la eficiencia energetica entre platos

Metodo <=>



124
125
126
127
# File 'lib/pract06/plato_herencia.rb', line 124

def <=>(other)
  return nil unless other.kind_of? Plato_herencia
  @valor <=> other.valor
end

#huella_nutricionalObject

Deprecated.

Funcion que halla la huella nutricional

Metodo huella nutricional



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/pract06/plato_herencia.rb', line 87

def huella_nutricional

  @huella_energetica

  if @valor <= 670
    @huella_energetica = 1.0
  elsif @valor > 670 && @valor <= 830
    @huella_energetica = 2.0
  else  
    @huella_energetica = 3.0
  end

  @huella_carbono

  if @total_ve <= 800
    @huella_carbono = 1.0
  elsif @total_ve > 800 && @total_ve <= 1200
    @huella_carbono = 2.0
  else 
    @huella_carbono = 3.0
  end

  return (@huella_energetica+@huella_carbono)/2

end

#metros_cuadrados(x_metros_cuadrados) ⇒ Object

Deprecated.

Sirve para hallar los metodos cuadrados del plato

Metodo metros_cuadrados



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pract06/plato_herencia.rb', line 47

def metros_cuadrados(x_metros_cuadrados)

  total_mc = 0
  i = 0

  while i < x_metros_cuadrados.length do

    total_mc += x_metros_cuadrados[i] + total_mc

    i += 1

  end 

  return total_mc

end

#to_sObject

Deprecated.

Da la eficiencia energetica formateada

Metodo to_s



116
117
118
119
# File 'lib/pract06/plato_herencia.rb', line 116

def to_s

  "Eficiencia energética = #{valor}"
end

#total_veObject

Deprecated.

Funcion para hallar las emisiones totales del plato

Metodo Emisiones totales del plato



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pract06/plato_herencia.rb', line 27

def total_ve
  
  total_ve = 0
  i = 0
  
  while i < conjunto_alimentos.length do
  
    total_ve += conjunto_alimentos[i].gei + total_ve
    i += 1

  end

  return total_ve
end

#valorObject

Deprecated.

Funcion para hallar el valor energetico del plato heredado

Metodo valor



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/pract06/plato_herencia.rb', line 68

def valor

  i = 0
  valor = 0
  while i < conjunto_alimentos.length do

    valor = conjunto_alimentos[i].valor_energetico + valor

    i += 1

  end

  return valor
end