Class: Diet

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

Direct Known Subclasses

MenuAge, MenuFood

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ttl, dip, vct, pprtn, pfts, pchdt) ⇒ Diet

Returns a new instance of Diet

Parameters:

  • Título, (String)
    String

    Ingesta diaria, [String] Valor calorífico,

  • Porcentaje (String)

    de proteínas, [String] Porcentaje de proteínas, [String] Porcentaje de grasas

  • Porcentaje (String)

    de hidratos de carbono



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/prct06/prct06.rb', line 34

def initialize(ttl,dip,vct,pprtn,pfts,pchdt)
    
    @ttl   = ttl #Título
    
    @dip   = dip #Ingesta Diaria
   	
   	@vct   =  vct #Valor calorífico Total
   	
   	@rcps  = Array.new #Array de platos
    
    @pprtn = pprtn #Porcentaje de proteínas
    
    @pfts  = pfts #Porcentaje de grasas
   	
   	@pchdt = pchdt #Porcentaje de hidratos de carbono

end

Instance Attribute Details

#MObject



17
18
19
# File 'lib/prct06/prct06.rb', line 17

def dip
  @dip
end

#MObject



27
28
29
# File 'lib/prct06/prct06.rb', line 27

def pchdt
  @pchdt
end

#MObject



25
26
27
# File 'lib/prct06/prct06.rb', line 25

def pfts
  @pfts
end

#MObject



23
24
25
# File 'lib/prct06/prct06.rb', line 23

def pprtn
  @pprtn
end

#MObject



21
22
23
# File 'lib/prct06/prct06.rb', line 21

def rcps
  @rcps
end

#MObject



15
16
17
# File 'lib/prct06/prct06.rb', line 15

def ttl
  @ttl
end

#MObject



19
20
21
# File 'lib/prct06/prct06.rb', line 19

def vct
  @vct
end

Instance Method Details

#<=>(other) ⇒ Int

Note:

Función que permite comparar dos dietas en función de sus valor calorífico.

Returns 1 if self>other, 0 if self == other, -1 if self<other

Parameters:

  • Menú (Diet)

    a comparar

Returns:

  • (Int)

    1 if self>other, 0 if self == other, -1 if self<other



92
93
94
95
96
# File 'lib/prct06/prct06.rb', line 92

def <=>(other) 

	@vct <=> other.vct

end

#new_recipe(recipe) ⇒ Object

Con este método añadimos en el array un nuevo plato siguiendo el formato predefinido.



80
81
82
83
84
85
86
# File 'lib/prct06/prct06.rb', line 80

def new_recipe(recipe)
	
	tmp = "- #{recipe}\n"
	
	rcps << tmp

end

#to_sString

Returns String con el contenido de la lista

Returns:

  • (String)

    String con el contenido de la lista



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/prct06/prct06.rb', line 55

def to_s()

	tmp = "#{ttl} (#{dip}%)\n"

	i   = 0

	begin

		tmp += "#{rcps[i]}"

		i+=1

	end while (i<rcps.length)

	tmp += "V.C.T. | %      #{vct} kcal | #{pprtn}% - #{pfts}% - #{pchdt}%\n"
	
	"#{tmp}"
end