Class: Alimento_
- Inherits:
-
Object
- Object
- Alimento_
- Includes:
- Comparable
- Defined in:
- lib/alimento/alimento_.rb
Overview
Clase Alimento que representa a un alimento con el nombre y otros datos del mismo En alimento se incluye el mixin Comparable
Direct Known Subclasses
Instance Attribute Summary collapse
-
#datos ⇒ Object
Returns the value of attribute datos.
-
#fats ⇒ Object
readonly
Returns the value of attribute fats.
-
#glucids ⇒ Object
readonly
Returns the value of attribute glucids.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#proteins ⇒ Object
readonly
Returns the value of attribute proteins.
Instance Method Summary collapse
-
#<=>(another) ⇒ Object
Se define para incluir el mixin comparable Se toma como valor para la comparación el valor energético.
-
#aibc(indice) ⇒ Object
Devuelve el valor del AIBC de un alimento para un individuo concreto.
-
#initialize(name, proteins, glucids, fats) ⇒ Alimento_
constructor
Se asignan el nombre, las proteinas, los glucidos y las grasas.
-
#to_s ⇒ Object
Formatea la salida a texto.
-
#valor_energetico ⇒ Object
Devuelve el valor energético.
Constructor Details
#initialize(name, proteins, glucids, fats) ⇒ Alimento_
Se asignan el nombre, las proteinas, los glucidos y las grasas
21 22 23 24 25 26 |
# File 'lib/alimento/alimento_.rb', line 21 def initialize(name, proteins, glucids, fats) @name = name @proteins = proteins @glucids = glucids @fats = fats end |
Instance Attribute Details
#datos ⇒ Object
Returns the value of attribute datos.
19 20 21 |
# File 'lib/alimento/alimento_.rb', line 19 def datos @datos end |
#fats ⇒ Object (readonly)
Returns the value of attribute fats.
18 19 20 |
# File 'lib/alimento/alimento_.rb', line 18 def fats @fats end |
#glucids ⇒ Object (readonly)
Returns the value of attribute glucids.
18 19 20 |
# File 'lib/alimento/alimento_.rb', line 18 def glucids @glucids end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/alimento/alimento_.rb', line 18 def name @name end |
#proteins ⇒ Object (readonly)
Returns the value of attribute proteins.
18 19 20 |
# File 'lib/alimento/alimento_.rb', line 18 def proteins @proteins end |
Instance Method Details
#<=>(another) ⇒ Object
Se define para incluir el mixin comparable Se toma como valor para la comparación el valor energético
39 40 41 42 |
# File 'lib/alimento/alimento_.rb', line 39 def <=> (another) return nil unless another.is_a? Alimento_ self.valor_energetico <=> another.valor_energetico end |
#aibc(indice) ⇒ Object
Devuelve el valor del AIBC de un alimento para un individuo concreto
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/alimento/alimento_.rb', line 44 def aibc(indice) vector = [] datos[indice][1..datos[indice].length-1].zip(datos[indice][0..datos[indice].length-2]) do | gi, gi_1 | if gi < datos[indice][0] vector << 0.0 else vector << (((gi-datos[indice][0])+(gi_1-datos[indice][0]))/2)*5 end end vector.reduce(:+) end |
#to_s ⇒ Object
Formatea la salida a texto
28 29 30 31 32 |
# File 'lib/alimento/alimento_.rb', line 28 def to_s string = ("#{@name}\t#{@proteins}\t#{@glucids}\t#{@fats}") # puts string # return string end |
#valor_energetico ⇒ Object
Devuelve el valor energético
34 35 36 |
# File 'lib/alimento/alimento_.rb', line 34 def valor_energetico v_e = (@proteins*4)+(@glucids*4)+(@fats*9) end |