Class: Diet

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/dieta/dieta.rb

Direct Known Subclasses

DietaDSL, Menu_g_a, Menu_grupo_e

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(comida, porciones, calorias) ⇒ Diet

Returns a new instance of Diet.



4
5
6
7
8
9
# File 'lib/dieta/dieta.rb', line 4

def initialize(comida,porciones,calorias)
    #atributos
    @comida = comida
    @porciones = porciones
    @calorias = calorias
end

Instance Attribute Details

#caloriasObject

Returns the value of attribute calorias.



3
4
5
# File 'lib/dieta/dieta.rb', line 3

def calorias
  @calorias
end

#comidaObject

Returns the value of attribute comida.



3
4
5
# File 'lib/dieta/dieta.rb', line 3

def comida
  @comida
end

#porcionesObject

Returns the value of attribute porciones.



3
4
5
# File 'lib/dieta/dieta.rb', line 3

def porciones
  @porciones
end

Instance Method Details

#<=>(anOther) ⇒ Object



53
54
55
# File 'lib/dieta/dieta.rb', line 53

def <=> (anOther)
  self.calorias <=> anOther.calorias
end

#==(anOther) ⇒ Object



57
58
59
# File 'lib/dieta/dieta.rb', line 57

def ==(anOther)
  return (calorias== anOther.calorias)
end

#calorias_to_sObject

calorias_to_s



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dieta/dieta.rb', line 40

def calorias_to_s
  
  i = 0
  aux = "V.C.T:"
  while i < (@calorias.size - 1)
    aux = "#{aux}" + "#{" "}" + "#{@calorias[i]}" + "#{","}"
    i = i + 1
  end
  aux="#{aux}" + "#{" "}" + "#{@calorias[i]}"
  return aux
    
end

#comida_to_sObject

comida_to_s



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dieta/dieta.rb', line 12

def comida_to_s
  
  i = 0
  aux="#{@comida[i]}"
  i=i+1
  while i < @comida.size
      aux = "#{aux}" + "#{" "}" + "#{@comida[i]}"
      i = i + 1
  end
  aux="#{aux}" + "#{"\n"}" 
  
  return aux
end

#porciones_to_sObject

porciones_to_s



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dieta/dieta.rb', line 27

def porciones_to_s
  
  i = 0
  aux = "Porciones:\n"
  while i < @porciones.size
    aux = "#{aux}" + "#{" "}" + "#{@porciones[i][0]}" + "#{", "}" + "#{@porciones[i][1]}\n"
    i = i + 1
  end
  
  return aux
end