Class: DietaNueva_t

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(titulo, &block) ⇒ DietaNueva_t

Returns a new instance of DietaNueva_t.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/prct06/diet.rb', line 7

def initialize(titulo, &block)
  self.titulo = titulo
  self.porcediarios = []
  self.platos = []
  self.porcentajes = []

  if block_given?
    if block.arity == 1
      yield self
    else
      instance_eval(&block)
    end
  end
end

Instance Attribute Details

#platosObject

Returns the value of attribute platos.



5
6
7
# File 'lib/prct06/diet.rb', line 5

def platos
  @platos
end

#porcediariosObject

Returns the value of attribute porcediarios.



5
6
7
# File 'lib/prct06/diet.rb', line 5

def porcediarios
  @porcediarios
end

#porcentajesObject

Returns the value of attribute porcentajes.



5
6
7
# File 'lib/prct06/diet.rb', line 5

def porcentajes
  @porcentajes
end

#tituloObject

Returns the value of attribute titulo.



5
6
7
# File 'lib/prct06/diet.rb', line 5

def titulo
  @titulo
end

Instance Method Details

#plato(options = {}) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/prct06/diet.rb', line 49

def plato(options = {})

  plato = " #{options[:descripcion]}." if options[:descripcion]
  plato += " #{options[:porciones]}." if options[:porciones]
  plato += " #{options[:ingengr]}.\n" if options[:ingengr]

  platos << plato
end

#porcediario(options = {}) ⇒ Object



44
45
46
47
# File 'lib/prct06/diet.rb', line 44

def porcediario(options = {})
  porcediarios << "\nMin: #{options[:minimo]}" if options[:minimo]
  porcediarios << "\nMax: #{options[:maximo]}\n\n" if options[:maximo]
end

#porcentaje(options = {}) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/prct06/diet.rb', line 59

def porcentaje(options = {})

  porcentajes << "#{options[:vct]} kcal" if options[:vct]
  porcentajes << "#{options[:porcproteinas]}%" if options[:porcproteinas]
  porcentajes << "#{options[:porcgrasas]}%" if options[:porcgrasas]
  porcentajes << "#{options[:porchidratos]}%." if options[:porchidratos]
end

#to_sObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/prct06/diet.rb', line 22

def to_s
   mostrar = titulo
   mostrar << "\n#{'=' * titulo.size}\n"

   mostrar << "\nPorcentajes recomendados de ingesta."
   porcediarios.each do |porcediario|
     mostrar << "#{porcediario}"
   end

   platos.each_with_index do |plato, i|
     mostrar << "#{i + 1} #{plato}"
   end


   mostrar << "\nV.C.T. y porcentajes: "
   porcentajes.each do |porcentaje|
     mostrar << " #{porcentaje}"
   end

   mostrar << "\n\n"
end