Class: Diet
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Int
1 if self>other, 0 if self == other, -1 if self<other.
-
#initialize(ttl, dip, vct, pprtn, pfts, pchdt) ⇒ Diet
constructor
A new instance of Diet.
-
#new_recipe(recipe) ⇒ Object
Con este método añadimos en el array un nuevo plato siguiendo el formato predefinido.
-
#to_s ⇒ String
String con el contenido de la lista.
Constructor Details
#initialize(ttl, dip, vct, pprtn, pfts, pchdt) ⇒ Diet
Returns a new instance of Diet
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
#M ⇒ Object
17 18 19 |
# File 'lib/prct06/prct06.rb', line 17 def dip @dip end |
#M ⇒ Object
27 28 29 |
# File 'lib/prct06/prct06.rb', line 27 def pchdt @pchdt end |
#M ⇒ Object
25 26 27 |
# File 'lib/prct06/prct06.rb', line 25 def pfts @pfts end |
#M ⇒ Object
23 24 25 |
# File 'lib/prct06/prct06.rb', line 23 def pprtn @pprtn end |
#M ⇒ Object
21 22 23 |
# File 'lib/prct06/prct06.rb', line 21 def rcps @rcps end |
#M ⇒ Object
15 16 17 |
# File 'lib/prct06/prct06.rb', line 15 def ttl @ttl end |
#M ⇒ Object
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
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_s ⇒ String
Returns 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 |