Class: Plato

Inherits:
Plato_i show all
Includes:
Comparable
Defined in:
lib/p6/plato.rb

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

Plato_dsl

Instance Attribute Summary collapse

Attributes inherited from Plato_i

#alimentos_, #nombre_, #peso_

Instance Method Summary collapse

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_totalObject

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_nutricionalObject

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

#impactoObject

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_totalObject

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