Class: Diet
- Inherits:
-
Object
- Object
- Diet
- Defined in:
- lib/practica7/diet.rb
Instance Attribute Summary collapse
-
#con_plato ⇒ Object
Returns the value of attribute con_plato.
-
#data ⇒ Object
Returns the value of attribute data.
-
#des_plato ⇒ Object
Returns the value of attribute des_plato.
-
#inges ⇒ Object
Returns the value of attribute inges.
-
#nombre ⇒ Object
Returns the value of attribute nombre.
-
#percentage ⇒ Object
Returns the value of attribute percentage.
-
#plat ⇒ Object
Returns the value of attribute plat.
-
#porcen ⇒ Object
Returns the value of attribute porcen.
-
#titulo ⇒ Object
Returns the value of attribute titulo.
-
#vct ⇒ Object
Returns the value of attribute vct.
Instance Method Summary collapse
- #group_plates ⇒ Object
- #ingesta(options = {}) ⇒ Object
-
#initialize(nomb, &block) ⇒ Diet
constructor
A new instance of Diet.
- #plato(options = {}) ⇒ Object
- #porcentajes(options = {}) ⇒ Object
- #title(name) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(nomb, &block) ⇒ Diet
Returns a new instance of Diet.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/practica7/diet.rb', line 4 def initialize(nomb,&block) self.nombre = nomb self.titulo="" self.inges=[] self.plat=[] self.porcen=[] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#con_plato ⇒ Object
Returns the value of attribute con_plato.
3 4 5 |
# File 'lib/practica7/diet.rb', line 3 def con_plato @con_plato end |
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/practica7/diet.rb', line 3 def data @data end |
#des_plato ⇒ Object
Returns the value of attribute des_plato.
3 4 5 |
# File 'lib/practica7/diet.rb', line 3 def des_plato @des_plato end |
#inges ⇒ Object
Returns the value of attribute inges.
3 4 5 |
# File 'lib/practica7/diet.rb', line 3 def inges @inges end |
#nombre ⇒ Object
Returns the value of attribute nombre.
3 4 5 |
# File 'lib/practica7/diet.rb', line 3 def nombre @nombre end |
#percentage ⇒ Object
Returns the value of attribute percentage.
3 4 5 |
# File 'lib/practica7/diet.rb', line 3 def percentage @percentage end |
#plat ⇒ Object
Returns the value of attribute plat.
3 4 5 |
# File 'lib/practica7/diet.rb', line 3 def plat @plat end |
#porcen ⇒ Object
Returns the value of attribute porcen.
3 4 5 |
# File 'lib/practica7/diet.rb', line 3 def porcen @porcen end |
#titulo ⇒ Object
Returns the value of attribute titulo.
3 4 5 |
# File 'lib/practica7/diet.rb', line 3 def titulo @titulo end |
#vct ⇒ Object
Returns the value of attribute vct.
3 4 5 |
# File 'lib/practica7/diet.rb', line 3 def vct @vct end |
Instance Method Details
#group_plates ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/practica7/diet.rb', line 38 def group_plates s = "#{self.con_plato[0][0]}" $i=1 while $i < self.con_plato.length do s+= ", " s+= "#{self.con_plato[$i][0]}" $i+=1 end s end |
#ingesta(options = {}) ⇒ Object
21 22 23 24 |
# File 'lib/practica7/diet.rb', line 21 def ingesta(={}) inges << " (#{[:min]})" if [:min] inges << " (#{[:max]})" if [:max] end |
#plato(options = {}) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/practica7/diet.rb', line 25 def plato(={}) vec_plat = "(#{[:descripcion]})" if [:descripcion] vec_plat << "(#{[:porcion]})" if [:porcion] vec_plat << "(#{[:gramos]})" if [:gramos] plat<<vec_plat end |
#porcentajes(options = {}) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/practica7/diet.rb', line 31 def porcentajes(={}) porcen<<"(#{[:vct]})" if [:vct] porcen<<"(#{[:proteinas]})" if [:proteinas] porcen<<"(#{[:grasas]})" if [:grasas] porcen<<"(#{[:hidratos]})" if [:hidratos] end |
#title(name) ⇒ Object
18 19 20 |
# File 'lib/practica7/diet.rb', line 18 def title(name) self.titulo=name end |
#to_s ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/practica7/diet.rb', line 48 def to_s output= "\n\n#{self.nombre}" output << "\n#{'=' * titulo.size}\n\n" output << "Ingesta min:#{inges[0]} max:#{inges[1]}\n\n" plat.each do |n| output<<"#{n}\n" end output <<"\n\n" output << "vct: #{porcen[0]} protinas: #{porcen[1]} grasas: #{porcen[2]} hidratos: #{porcen[3]}" end |