Class: Alimento

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

Overview

Author

Eduardo Estévez Rodríguez ([email protected])

Copyright

Cretive Commons

License

Distributes under the same terms as Ruby

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(no, pr, ca, li, gei, te) ⇒ Alimento

Se asigna el nombre del alimento junto con su información nutricional e impacto ambiental



16
17
18
19
20
21
22
23
# File 'lib/feeding/alimento.rb', line 16

def initialize(no,pr,ca,li,gei,te)
  @no = no
  @pr = pr
  @ca = ca
  @li = li
  @gei = gei
  @te = te
end

Instance Attribute Details

#caObject (readonly)

Se ha incluido el mixin Comparable



12
13
14
# File 'lib/feeding/alimento.rb', line 12

def ca
  @ca
end

#geiObject (readonly)

Se ha incluido el mixin Comparable



12
13
14
# File 'lib/feeding/alimento.rb', line 12

def gei
  @gei
end

#liObject (readonly)

Se ha incluido el mixin Comparable



12
13
14
# File 'lib/feeding/alimento.rb', line 12

def li
  @li
end

#noObject (readonly)

Se ha incluido el mixin Comparable



12
13
14
# File 'lib/feeding/alimento.rb', line 12

def no
  @no
end

#prObject (readonly)

Se ha incluido el mixin Comparable



12
13
14
# File 'lib/feeding/alimento.rb', line 12

def pr
  @pr
end

#teObject (readonly)

Se ha incluido el mixin Comparable



12
13
14
# File 'lib/feeding/alimento.rb', line 12

def te
  @te
end

Instance Method Details

#<=>(other) ⇒ Object

Se define para incluir el mixin comparable tomando como valor para la comparación la cantidad de kcalorías que posee el alimento



86
87
88
# File 'lib/feeding/alimento.rb', line 86

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

#carbohidratosObject

Devuelve la cantidad de carbohidratos que posee



36
37
38
# File 'lib/feeding/alimento.rb', line 36

def carbohidratos
  @ca
end

#gasesObject

Devuelve la cantidad de gases que emite anualmente



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

def gases 
  @gei
end

#impacto(gr, alimento1, a1gr, alimento2, a2gr, alimento3, a3gr, alimento4, a4gr) ⇒ Object

Devuelve el impacto ambiental diario que genera la alimentación de una persona adulta



66
67
68
69
70
71
72
73
# File 'lib/feeding/alimento.rb', line 66

def impacto(gr, alimento1,a1gr, alimento2,a2gr, alimento3,a3gr, alimento4,a4gr)
  v_impacto = []

  v_impacto[0] = (porcion_gases(gr) + alimento1.porcion_gases(a1gr) + alimento2.porcion_gases(a2gr) + alimento3.porcion_gases(a3gr) + alimento4.porcion_gases(a4gr)).round(2)
  v_impacto[1] = (porcion_terreno(gr) + alimento1.porcion_terreno(a1gr) + alimento2.porcion_terreno(a2gr) + alimento3.porcion_terreno(a3gr) + alimento4.porcion_terreno(a4gr)).round(2)

  v_impacto.to_s
end

#kcalObject

Devuelve la cantidad de kcalorías que aporta



61
62
63
# File 'lib/feeding/alimento.rb', line 61

def kcal 
  (@pr * 4 + @ca * 4 + @li * 9).round(2)
end

#lipidosObject

Devuelve la cantidad de lipidos que posee



41
42
43
# File 'lib/feeding/alimento.rb', line 41

def lipidos
  @li
end

#nameObject

Devuelve el nombre del alimento



26
27
28
# File 'lib/feeding/alimento.rb', line 26

def name
  @no
end

#porcion_gases(gramos) ⇒ Object

Calcula la cantidad de gases que emite cierta cantidad de gramos del alimento



76
77
78
# File 'lib/feeding/alimento.rb', line 76

def porcion_gases(gramos)
  gases = ((gramos * @gei) / 1000).round(2)
end

#porcion_terreno(gramos) ⇒ Object

Calcula la cantidad de terreno que utiliza cierta cantidad de gramos del alimento para su producción



81
82
83
# File 'lib/feeding/alimento.rb', line 81

def porcion_terreno(gramos)
  metros = ((gramos * @te) / 1000).round(2)
end

#proteinaObject

Devuelve la cantidad de proteínas que posee



31
32
33
# File 'lib/feeding/alimento.rb', line 31

def proteina
  @pr
end

#terrenoObject

Devuelve la cantidad de terreno que usa para su producción



51
52
53
# File 'lib/feeding/alimento.rb', line 51

def terreno
  @te
end

#to_sObject

Devuelve el alimento formateado



56
57
58
# File 'lib/feeding/alimento.rb', line 56

def to_s
  "(#{@no}, #{@pr}, #{@ca}, #{@li}, #{@gei}, #{@te})"
end