Class: Alimento
- Inherits:
-
Object
- Object
- Alimento
- Includes:
- Comparable
- Defined in:
- lib/nutriente/alimento.rb
Instance Attribute Summary collapse
-
#carbohidratos ⇒ Object
readonly
Returns the value of attribute carbohidratos.
-
#gei ⇒ Object
readonly
Returns the value of attribute gei.
-
#lipidos ⇒ Object
readonly
Returns the value of attribute lipidos.
-
#nombre ⇒ Object
readonly
Returns the value of attribute nombre.
-
#proteinas ⇒ Object
readonly
Returns the value of attribute proteinas.
-
#terreno ⇒ Object
readonly
Returns the value of attribute terreno.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Metodo de comparación, devuelve -1 si es menor que other, +1 si es mayor y 0 si es igual, se utiliza para los mixins de comparable.
-
#energiaGlucidos ⇒ Object
Obtiene la energía de los glúcidos.
-
#energiaLipidos ⇒ Object
Obtiene la energía de los lipidos.
-
#energiaProteinas ⇒ Object
Obtiene la energía de las proteínas.
-
#initialize(nombre, proteinas, carbohidratos, lipidos, gei, terreno) ⇒ Alimento
constructor
Contruye un objeto alimento según los parámetros.
-
#to_s ⇒ Object
Devuelve los valores del alimento formateados como un string.
-
#valorEnergetico ⇒ Object
Calcula el valor energético total.
Constructor Details
#initialize(nombre, proteinas, carbohidratos, lipidos, gei, terreno) ⇒ Alimento
Contruye un objeto alimento según los parámetros
17 18 19 20 21 22 23 24 |
# File 'lib/nutriente/alimento.rb', line 17 def initialize(nombre, proteinas, carbohidratos, lipidos, gei, terreno) @nombre = nombre @proteinas = proteinas @carbohidratos = carbohidratos @lipidos = lipidos @gei = gei @terreno = terreno end |
Instance Attribute Details
#carbohidratos ⇒ Object (readonly)
Returns the value of attribute carbohidratos.
13 14 15 |
# File 'lib/nutriente/alimento.rb', line 13 def carbohidratos @carbohidratos end |
#gei ⇒ Object (readonly)
Returns the value of attribute gei.
13 14 15 |
# File 'lib/nutriente/alimento.rb', line 13 def gei @gei end |
#lipidos ⇒ Object (readonly)
Returns the value of attribute lipidos.
13 14 15 |
# File 'lib/nutriente/alimento.rb', line 13 def lipidos @lipidos end |
#nombre ⇒ Object (readonly)
Returns the value of attribute nombre.
13 14 15 |
# File 'lib/nutriente/alimento.rb', line 13 def nombre @nombre end |
#proteinas ⇒ Object (readonly)
Returns the value of attribute proteinas.
13 14 15 |
# File 'lib/nutriente/alimento.rb', line 13 def proteinas @proteinas end |
#terreno ⇒ Object (readonly)
Returns the value of attribute terreno.
13 14 15 |
# File 'lib/nutriente/alimento.rb', line 13 def terreno @terreno end |
Instance Method Details
#<=>(other) ⇒ Object
Metodo de comparación, devuelve -1 si es menor que other, +1 si es mayor y 0 si es igual, se utiliza para los mixins de comparable
52 53 54 |
# File 'lib/nutriente/alimento.rb', line 52 def <=>(other) return self.valorEnergetico <=> other.valorEnergetico end |
#energiaGlucidos ⇒ Object
Obtiene la energía de los glúcidos
37 38 39 |
# File 'lib/nutriente/alimento.rb', line 37 def energiaGlucidos() @carbohidratos * 4 end |
#energiaLipidos ⇒ Object
Obtiene la energía de los lipidos
32 33 34 |
# File 'lib/nutriente/alimento.rb', line 32 def energiaLipidos() @lipidos * 9 end |
#energiaProteinas ⇒ Object
Obtiene la energía de las proteínas
27 28 29 |
# File 'lib/nutriente/alimento.rb', line 27 def energiaProteinas() @proteinas * 4 end |
#to_s ⇒ Object
Devuelve los valores del alimento formateados como un string
47 48 49 |
# File 'lib/nutriente/alimento.rb', line 47 def to_s() "#{@nombre}, #{@proteinas}g, #{@carbohidratos}g, #{@lipidos}g, #{@gei} kgCO2eq, #{@terreno} m2año" end |
#valorEnergetico ⇒ Object
Calcula el valor energético total
42 43 44 |
# File 'lib/nutriente/alimento.rb', line 42 def valorEnergetico() energiaProteinas() + energiaLipidos() + energiaGlucidos() end |