Class: Comida
- Inherits:
-
Object
- Object
- Comida
- Defined in:
- lib/alimento/comida.rb
Instance Method Summary collapse
-
#get_aibc ⇒ Object
método que nos devuelve el calculo del aibc del alimento.
- #get_nombre ⇒ Object
-
#initialize(nombre, tiempo, concentraciones) ⇒ Comida
constructor
método inicializar clase.
-
#to_s ⇒ Object
salida por pantalla de clase.
Constructor Details
#initialize(nombre, tiempo, concentraciones) ⇒ Comida
método inicializar clase
3 4 5 6 7 8 |
# File 'lib/alimento/comida.rb', line 3 def initialize(nombre, tiempo,concentraciones) # atributos @nombre = nombre @concentraciones = concentraciones @tiempo = tiempo end |
Instance Method Details
#get_aibc ⇒ Object
método que nos devuelve el calculo del aibc del alimento
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/alimento/comida.rb', line 15 def get_aibc() #metodo imperativo #total = 0 #for j in [email protected] # aux=@concentraciones[j].to_f-@concentraciones[0].to_f # aux2=@concentraciones[j-1].to_f-@concentraciones[0].to_f # if aux < 0 # aux=0 # end # if aux2 < 0 # aux2=0 # end # aux3=aux+aux2 # aux3=aux3*@tiempo.to_f # aux3=aux3/2 # total=total+aux3 #end #otro metodo s=[] @concentraciones[1..@concentraciones.length-1].zip(@concentraciones[0..@concentraciones.length-2]) do |x,y| if x < @concentraciones[0] s << 0.0 else s << (((x - @concentraciones[0])+(y-@concentraciones[0]))/2)*5 end end #puts s.reduce(:+).round(2) #puts total.round(2) #return total.round(2) return s.reduce(:+).round(2) end |
#get_nombre ⇒ Object
10 11 12 |
# File 'lib/alimento/comida.rb', line 10 def get_nombre() return @nombre end |
#to_s ⇒ Object
salida por pantalla de clase
49 50 51 52 53 54 55 56 57 |
# File 'lib/alimento/comida.rb', line 49 def to_s s = "\n" s << "#{@nombre}\n" s << "\nConcentraciones: #{@concentraciones}" s << "\nPeriodo de Tiempo: #{@tiempo} minutos" s << "\n" s << "\nAIBC: " + get_aibc.to_s s end |