Class: Alimento

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/p6/p6.rb

Overview

Clase alimento, contiene toda la información para describir un alimento

Author:

  • Guillermo Hernández González

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n, pro, ch, l, g, te) ⇒ Alimento

Crea un alimento tras pasarle una serie de parámetros



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

def initialize(n , pro , ch , l , g , te) 
    @nombre= n
    @proteinas= pro
    @carbohidratos= ch
    @lipidos= l
    @gases= g
    @terreno = te 
end

Instance Attribute Details

#carbohidratosObject (readonly)

devuelve la cantidad de carbohidratos del alimento

Returns:

  • (Object)

    the current value of carbohidratos



9
10
11
# File 'lib/p6/p6.rb', line 9

def carbohidratos
  @carbohidratos
end

#gasesObject (readonly)

devuelve las emisiones de gases diarias de un alimento

Returns:

  • (Object)

    the current value of gases



9
10
11
# File 'lib/p6/p6.rb', line 9

def gases
  @gases
end

#lipidosObject (readonly)

devuelve la cantidad de lipidos contenidos del alimento

Returns:

  • (Object)

    the current value of lipidos



9
10
11
# File 'lib/p6/p6.rb', line 9

def lipidos
  @lipidos
end

#nombreObject (readonly)

devuelve el nombre del alimento

Returns:

  • (Object)

    the current value of nombre



9
10
11
# File 'lib/p6/p6.rb', line 9

def nombre
  @nombre
end

#proteinasObject (readonly)

devuelve la cantidad de proteinas contenidos del alimento

Returns:

  • (Object)

    the current value of proteinas



9
10
11
# File 'lib/p6/p6.rb', line 9

def proteinas
  @proteinas
end

#terrenoObject (readonly)

devuelve el terreno necesario para cultivar el alimento

Returns:

  • (Object)

    the current value of terreno



9
10
11
# File 'lib/p6/p6.rb', line 9

def terreno
  @terreno
end

Instance Method Details

#<=>(other) ⇒ Object



46
47
48
# File 'lib/p6/p6.rb', line 46

def <=>(other)
    val_ener <=> other.val_ener
end

#impac_ambien(array) ⇒ Object



40
41
42
43
44
# File 'lib/p6/p6.rb', line 40

def impac_ambien array
    total = 0
    total = array.sum { |array| array.gases + array.terreno }            
    return total
end

#to_stringObject

Devuelve cada uno de los parámetros de Alimento como una string



25
26
27
# File 'lib/p6/p6.rb', line 25

def to_string()
    "Nombre: #{@nombre} \n Proteínas: #{@proteinas} \n Carbohidratos: #{@carbohidratos} \n Lípidos: #{@lipidos} \n Gases de efecto invernadero: #{@gases} \n Terreno: #{@terreno} \n"
end

#val_enerObject

Calcula el valor energético del alimento



31
32
33
34
35
36
37
# File 'lib/p6/p6.rb', line 31

def val_ener
    kcal_ch = @carbohidratos*4
    kcal_lip = @lipidos*9
    kcal_pro = @proteinas*4

    return (kcal_ch + kcal_lip + kcal_pro)
end