class Plato_2

Clase Plato_2 que hereda de Plato

Attributes

eficiencia[R]
gei[R]
terreno[R]

Public Class Methods

huella(valor) click to toggle source
# File lib/practica/plato_herencia.rb, line 77
def self.huella(valor)
        @Indice_huella.call(valor)
end
new(lista, cantidad,nombre) click to toggle source
Calls superclass method Plato::new
# File lib/practica/plato_herencia.rb, line 14
def initialize (lista, cantidad,nombre) #constructor que recibe dos listas, de cantidad y de alientos, ademas del nombre del plato
        @gei = @terreno = @eficiencia = 0
        super(lista,cantidad,nombre)          #instanciamos la clase padre con los parametros dados
        self.calc_gei
        self.calc_terreno
        self.calc_eficiencia

        #creamos diferentes metodos lambda
        @Huella = ->{ #para  calcular solamente el INDICE nutricional

                (@Indice_energia.call + @Indice_Carbono.call)/2
        }

        @Indice_energia = -> {        # Para calcular el indice de Energia
                if @calorias<670 then
                        1
                elsif @calorias >= 670 && @calorias <= 830 then
                         2
                else
                         3
                end
        }
        @Indice_Carbono = -> {        #para calcular el indice de Carbono
                if @gei < 800  then
                        1
                elsif @gei >= 800 && @gei <= 1200 then

                        2
                else
                        3
                end
        }
        @Indice_huella = ->(huella){  #para obtener la huella segun el indice de la misma
                if huella == 1 then
                        "Baja"
                elsif huella == 2 then
                        "Regular"
                else
                        "Alta"
                end

        }


end

Public Instance Methods

+(other) click to toggle source
# File lib/practica/plato_herencia.rb, line 117
def +(other)

        @aux_list=lista
        @aux_list.insertar_list(other.lista)
                        
        @aux_cantidad=cantidad
        @aux_cantidad.insertar_list(other.cantidad)

        @Nuevo_plato= Plato_2.new(@aux_list,@aux_cantidad, self.nombre)
end
<=>(other) click to toggle source
# File lib/practica/plato_herencia.rb, line 128
def <=> (other)                # operador <=>
        
        if other.instance_of? Plato_2         # para una instancia de Plato_2
        
        self.get_huella <=> other.get_huella # lo hacemos segun la huella nutricional
        elsif other.is_a? Plato               # en caso de que sea una instancia de la clase Plato
                self.calorias <=> other.calorias     #lo hacemos segun las calorias totales de ambos objetos
        else
                return nil
        end

end
==(other) click to toggle source
Calls superclass method Plato#==
# File lib/practica/plato_herencia.rb, line 100
def == (other)         #operador de comparacion
        if other.instance_of? Plato_2 #en caso de que el objeto a comparar sea una instancia de Plato_2
        
        self.to_s == other.to_s               #comparamos ambos to_s
        elsif other.is_a? Plato  #en caso de que sea una instancia de Plato
                s = ""
                s<< super.to_s

                return (s == other.to_s)     #comnparamos segun el to_s de la clase super

        else
                
                false
        end

end
Calc_huella_nutri() click to toggle source
# File lib/practica/plato_herencia.rb, line 73
def Calc_huella_nutri  #metodo que llama a lambda para obtener la huella nutricional
        
        return @Indice_huella.call((@Indice_energia.call + @Indice_Carbono.call)/2)
end
calc_eficiencia() click to toggle source
# File lib/practica/plato_herencia.rb, line 91
def calc_eficiencia            # metodo que calcula la eficiencia energetica del plato
        @eficiencia= ((@calorias / @gei )+ @terreno).round(2)
end
calc_gei() click to toggle source
# File lib/practica/plato_herencia.rb, line 60
def calc_gei           #calculamos el GEI total del plato
        contador=0
        while( @lista[contador] != nil && @cantidad[contador] != nil)  do
                
                @gei=@gei + calcular_equivalente(@lista[contador].get_valor.gei , @cantidad[contador].get_valor) 
                contador = contador +1
        end
        
end
calc_terreno() click to toggle source
# File lib/practica/plato_herencia.rb, line 81
def calc_terreno               # metodo que obtiene el terreno total del plato
        contador=0
        while( @lista[contador] != nil && @cantidad[contador] != nil)  do
                
                @terreno=@terreno + calcular_equivalente(@lista[contador].get_valor.terreno , @cantidad[contador].get_valor)
                contador = contador +1
        end
        
end
get_huella() click to toggle source
# File lib/practica/plato_herencia.rb, line 69
def get_huella #metodo que llama al lambda para obtener el indice de la huella nutricional

        @Huella.call
end
to_s() click to toggle source
Calls superclass method Plato#to_s
# File lib/practica/plato_herencia.rb, line 95
def to_s               #metodo que da formato a al plato en un string
        s =""
        s << super.to_s               # llamamos al to_s de la clase super
        s = s+",#{@gei},#{@terreno}"
end