Class: Alimento::Alimentos
- Inherits:
-
Object
- Object
- Alimento::Alimentos
- Includes:
- Comparable
- Defined in:
- lib/alimento/alimentos.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#glucidos ⇒ Object
readonly
Returns the value of attribute glucidos.
-
#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.
Instance Method Summary collapse
-
#<=>(another) ⇒ Object
Incluido para poder utilizar los métodos del mixin Comparable.
-
#calcValEn ⇒ Object
Calcula y devuelve el valor energético del alimento.
-
#initialize(nombre, proteinas, glucidos, lipidos) ⇒ Alimentos
constructor
Se asigna el nombre, y la cantidad de proteínas, glúcidos y lípidos del alimento.
-
#to_s ⇒ Object
Operador de salida de la clase alimento.
Constructor Details
#initialize(nombre, proteinas, glucidos, lipidos) ⇒ Alimentos
Se asigna el nombre, y la cantidad de proteínas, glúcidos y lípidos del alimento
17 18 19 20 21 22 23 |
# File 'lib/alimento/alimentos.rb', line 17 def initialize(nombre, proteinas, glucidos, lipidos) @nombre = nombre @proteinas = proteinas @glucidos = glucidos @lipidos = lipidos end |
Instance Attribute Details
#glucidos ⇒ Object (readonly)
Returns the value of attribute glucidos.
14 15 16 |
# File 'lib/alimento/alimentos.rb', line 14 def glucidos @glucidos end |
#lipidos ⇒ Object (readonly)
Returns the value of attribute lipidos.
14 15 16 |
# File 'lib/alimento/alimentos.rb', line 14 def lipidos @lipidos end |
#nombre ⇒ Object (readonly)
Returns the value of attribute nombre.
14 15 16 |
# File 'lib/alimento/alimentos.rb', line 14 def nombre @nombre end |
#proteinas ⇒ Object (readonly)
Returns the value of attribute proteinas.
14 15 16 |
# File 'lib/alimento/alimentos.rb', line 14 def proteinas @proteinas end |
Instance Method Details
#<=>(another) ⇒ Object
Incluido para poder utilizar los métodos del mixin Comparable
39 40 41 42 43 44 45 46 |
# File 'lib/alimento/alimentos.rb', line 39 def <=>(another) compare = calcValEn <=> another.calcValEn if compare == 0 return @nombre <=> another.nombre else return compare end end |
#calcValEn ⇒ Object
Calcula y devuelve el valor energético del alimento
34 35 36 |
# File 'lib/alimento/alimentos.rb', line 34 def calcValEn (@proteinas * VAL_EN_PROTEINAS) + (@glucidos * VAL_EN_GLUCIDOS) + (@lipidos * VAL_EN_LIPIDOS) end |
#to_s ⇒ Object
Operador de salida de la clase alimento. Muestra el alimento con formato: Nombre Cantidad_de_Proteínas Cantidad_de_glúcidos Cantidad_de_lípidos Ej: Huevos fritos 14.1 0.0 19.5
29 30 31 |
# File 'lib/alimento/alimentos.rb', line 29 def to_s "#{@nombre}\t#{@proteinas}\t#{@glucidos}\t#{@lipidos}" end |