Class: Alimento
- Inherits:
-
Object
- Object
- Alimento
- Includes:
- Comparable
- Defined in:
- lib/prct06/valor_calorico.rb
Overview
Direct Known Subclasses
Instance Attribute Summary collapse
-
#datos ⇒ Object
Includes the module Comparable It have four values,name of the aliment, and the information of proteins, lipids and glucids.
-
#glucidos ⇒ Object
Includes the module Comparable It have four values,name of the aliment, and the information of proteins, lipids and glucids.
-
#lipidos ⇒ Object
Includes the module Comparable It have four values,name of the aliment, and the information of proteins, lipids and glucids.
-
#nombre ⇒ Object
Includes the module Comparable It have four values,name of the aliment, and the information of proteins, lipids and glucids.
-
#proteinas ⇒ Object
Includes the module Comparable It have four values,name of the aliment, and the information of proteins, lipids and glucids.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Alimento type of the class.
-
#==(other) ⇒ Object
Alimento type of the class.
- #AIBC(indice) ⇒ Object
-
#initialize(nombre, proteinas, glucidos, lipidos) ⇒ Object
constructor
Lista type of the class.
-
#to_s ⇒ String
The resulting of join all the information, name, proteins, glucids and lipids.
- #valor_calorico ⇒ Object
Constructor Details
#initialize(nombre, proteinas, glucidos, lipidos) ⇒ Object
Returns Lista type of the class.
17 18 19 20 21 22 |
# File 'lib/prct06/valor_calorico.rb', line 17 def initialize(nombre, proteinas, glucidos, lipidos) @nombre = nombre @proteinas = proteinas @glucidos = glucidos @lipidos = lipidos end |
Instance Attribute Details
#datos ⇒ Object
Includes the module Comparable It have four values,name of the aliment, and the information of proteins, lipids and glucids
10 11 12 |
# File 'lib/prct06/valor_calorico.rb', line 10 def datos @datos end |
#glucidos ⇒ Object
Includes the module Comparable It have four values,name of the aliment, and the information of proteins, lipids and glucids
10 11 12 |
# File 'lib/prct06/valor_calorico.rb', line 10 def glucidos @glucidos end |
#lipidos ⇒ Object
Includes the module Comparable It have four values,name of the aliment, and the information of proteins, lipids and glucids
10 11 12 |
# File 'lib/prct06/valor_calorico.rb', line 10 def lipidos @lipidos end |
#nombre ⇒ Object
Includes the module Comparable It have four values,name of the aliment, and the information of proteins, lipids and glucids
10 11 12 |
# File 'lib/prct06/valor_calorico.rb', line 10 def nombre @nombre end |
#proteinas ⇒ Object
Includes the module Comparable It have four values,name of the aliment, and the information of proteins, lipids and glucids
10 11 12 |
# File 'lib/prct06/valor_calorico.rb', line 10 def proteinas @proteinas end |
Instance Method Details
#<=>(other) ⇒ Object
Returns Alimento type of the class.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/prct06/valor_calorico.rb', line 28 def <=>(other) #operador != return nil unless other.is_a?Alimento #devuelve nil si no son de la clase Alimento los dos objetos if valor_calorico == other.valor_calorico return 0 else if valor_calorico < other.valor_calorico return -1 #devuelve true cuando es menor, y lo niega para conseguirlo negado, el operador < solo comprueba el menor else return 1 #devuelve true si es > end end end |
#==(other) ⇒ Object
Returns Alimento type of the class.
44 45 46 47 48 49 50 |
# File 'lib/prct06/valor_calorico.rb', line 44 def == (other) if other.is_a?Alimento valor_calorico == other.valor_calorico else false end end |
#AIBC(indice) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/prct06/valor_calorico.rb', line 60 def AIBC(indice) #indice = individuo aux=[] #zip --> coge dos vectores y genera pares, la pos 1 del vector 1 y la pos 2 del vector a los devuelve y los guardo en aux #de esta forma tendre en x la pos actual y en y la pos-1 para llevar a cabo la formula datos[indice][1..datos[indice].length - 1].zip(datos[indice][0..datos[indice].length - 2]) do |x,y| if x < datos[indice][0] aux << 0.0 else aux << (((x-datos[indice][0])+(y-datos[indice][0]))/2)*5 end end aux.reduce(:+) #sumatorio del vector auxiliar, es lo que devuelve el metodo end |
#to_s ⇒ String
Returns the resulting of join all the information, name, proteins, glucids and lipids.
53 54 55 |
# File 'lib/prct06/valor_calorico.rb', line 53 def to_s imprime = "#{@nombre}: #{@proteinas} #{@glucidos} #{@lipidos}" end |
#valor_calorico ⇒ Object
76 77 78 |
# File 'lib/prct06/valor_calorico.rb', line 76 def valor_calorico valor = (@proteinas * 4) + (@glucidos * 4) + (@lipidos * 9) end |