class Alimento::Alimento
Esta clase permite representar un alimento. Se ha incluido el mixin Comparable.
Attributes
glucidos[R]
lipidos[R]
nombre[R]
proteinas[R]
Public Class Methods
new(nombre, proteinas, glucidos, lipidos)
click to toggle source
Se guarda el nombre y valor para proteínas, glúcidos y lípidos.
# File lib/alimento/fuente.rb, line 23 def initialize(nombre, proteinas, glucidos, lipidos) @nombre, @proteinas, @glucidos, @lipidos = nombre.to_s, proteinas, glucidos, lipidos end
Public Instance Methods
<=>(other)
click to toggle source
Se define para incluir el mixin comparable Se usa como valor para la comparación el valor energético.
# File lib/alimento/fuente.rb, line 71 def <=>(other) return nil unless other.is_a?Alimento self.val_energ <=> other.val_energ end
==(other)
click to toggle source
# File lib/alimento/fuente.rb, line 76 def ==(other) if other.is_a?Alimento self.nombre == other.nombre && self.proteinas == other.proteinas && self.glucidos == other.glucidos && self.lipidos == other.lipidos else false end end
aibc(array)
click to toggle source
Calcula el área incremental bajo de la curva del array de datos que recibe.
# File lib/alimento/fuente.rb, line 33 def aibc(array) bfr = array.collect{|x| x-array[0]} res = array.drop(1).collect!{|x| if x < array[0] then 0.0 else x-array[0] end}.zip(bfr).collect!{|x, y| if x!=0.0 then (x+y)*2.5 else 0.0 end} res.reduce(:+) end
ind_glu(filename)
click to toggle source
Calcula el índice glucémico del alimento cuyos datos haya en el fichero que recibe.
# File lib/alimento/fuente.rb, line 40 def ind_glu(filename) file = File.new(filename.to_s, "r") number = file.gets inds = [] number.to_i.times { aux = file.gets.split(" ").collect{|x| x.to_f} inds << aux } glucs = [] number.to_i.times { aux = file.gets.split(" ").collect{|x| x.to_f} glucs << aux } inds.collect!{|x| aibc(x)} glucs.collect!{|x| aibc(x)} res = inds.zip(glucs).collect{|x, y| x/y*100}.reduce(:+)/2 end
to_s()
click to toggle source
Muestra la información del objeto formateada. Lo convierte a string.
# File lib/alimento/fuente.rb, line 65 def to_s "%-15s" % ["#{@nombre.capitalize}: "] + "#{@proteinas} #{@glucidos} #{@lipidos}" + " grupo: #{@grupo}" end
val_energ()
click to toggle source
Calcula el valor enérgetico del alimento.
# File lib/alimento/fuente.rb, line 28 def val_energ @proteinas*4+@glucidos*4+@lipidos*9 end