Class: Alimento
- Inherits:
-
Object
- Object
- Alimento
- Includes:
- Comparable
- Defined in:
- lib/tddAlimentos/alimento.rb
Overview
alimento.rb
- Autor
-
Himar Manuel Barquín Carrasco
- Web
Descripción
Clase que representa un alimento, con la información de las proteínas, carbohidratos, lípidos, gases de efecto invernadero y metros cuadrados de tierra consumida que provoca producir el alimento.
Métodos
-
to_s
-
energetic_value
-
<=>
Instance Attribute Summary collapse
-
#carbohydrates ⇒ Object
readonly
Returns the value of attribute carbohydrates.
-
#gei ⇒ Object
readonly
Returns the value of attribute gei.
-
#lipids ⇒ Object
readonly
Returns the value of attribute lipids.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#protein ⇒ Object
readonly
Returns the value of attribute protein.
-
#terrain ⇒ Object
readonly
Returns the value of attribute terrain.
Instance Method Summary collapse
-
#<=>(another) ⇒ Object
- Nos permite comparar alimentos por su valor energético Parámetros
- another: Otro plato que se compara con el invocante Devuelve
-
‘true’ si la comparación es verdadera.
-
#energetic_value ⇒ Object
- Calcula el valor energético del alimento Devuelve
-
Valor decimal con el valor energético.
-
#initialize(name, protein, carbohydrates, lipids, gei, terrain) ⇒ Alimento
constructor
- Constructor de la clase Alimento Parámetros
-
name: Nombre del alimento * protein: Proteínas del alimento * carbohydrates: Carbohidratos del alimento * lipids: Lípidos del alimento * gei: Gases de Efecto Invernadero que se producen al producir el alimento * terrain: Terreno que se usa para la producción del alimento.
-
-
#to_s ⇒ Object
- Imprime la información del alimento Devuelve
-
Cadena de texto con la información del alimento.
Constructor Details
#initialize(name, protein, carbohydrates, lipids, gei, terrain) ⇒ Alimento
Constructor de la clase Alimento
- Parámetros
-
name: Nombre del alimento
-
protein: Proteínas del alimento
-
carbohydrates: Carbohidratos del alimento
-
lipids: Lípidos del alimento
-
gei: Gases de Efecto Invernadero que se producen al producir el alimento
-
terrain: Terreno que se usa para la producción del alimento
29 30 31 |
# File 'lib/tddAlimentos/alimento.rb', line 29 def initialize (name, protein, carbohydrates, lipids, gei, terrain) @name, @protein, @carbohydrates, @lipids, @gei, @terrain = name, protein, carbohydrates, lipids, gei, terrain end |
Instance Attribute Details
#carbohydrates ⇒ Object (readonly)
Returns the value of attribute carbohydrates.
19 20 21 |
# File 'lib/tddAlimentos/alimento.rb', line 19 def carbohydrates @carbohydrates end |
#gei ⇒ Object (readonly)
Returns the value of attribute gei.
19 20 21 |
# File 'lib/tddAlimentos/alimento.rb', line 19 def gei @gei end |
#lipids ⇒ Object (readonly)
Returns the value of attribute lipids.
19 20 21 |
# File 'lib/tddAlimentos/alimento.rb', line 19 def lipids @lipids end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/tddAlimentos/alimento.rb', line 19 def name @name end |
#protein ⇒ Object (readonly)
Returns the value of attribute protein.
19 20 21 |
# File 'lib/tddAlimentos/alimento.rb', line 19 def protein @protein end |
#terrain ⇒ Object (readonly)
Returns the value of attribute terrain.
19 20 21 |
# File 'lib/tddAlimentos/alimento.rb', line 19 def terrain @terrain end |
Instance Method Details
#<=>(another) ⇒ Object
Nos permite comparar alimentos por su valor energético
- Parámetros
-
another: Otro plato que se compara con el invocante
- Devuelve
-
‘true’ si la comparación es verdadera. ‘false’ en otro caso
52 53 54 |
# File 'lib/tddAlimentos/alimento.rb', line 52 def <=> (another) self.energetic_value <=> another.energetic_value end |
#energetic_value ⇒ Object
Calcula el valor energético del alimento
- Devuelve
-
Valor decimal con el valor energético
43 44 45 |
# File 'lib/tddAlimentos/alimento.rb', line 43 def energetic_value 4 * @protein + 4 * @carbohydrates + 9 * @lipids end |
#to_s ⇒ Object
Imprime la información del alimento
- Devuelve
-
Cadena de texto con la información del alimento
36 37 38 |
# File 'lib/tddAlimentos/alimento.rb', line 36 def to_s "Nombre: #{@name}\nProteínas (g): #{@protein}\nCarbohidratos (g): #{@carbohydrates}\nLípidos (g): #{@lipids}\nGEI (kgCO2eq): #{@gei}\nTerreno (m2 año): #{@terrain}\n" end |