Class: Menu_dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/prct11/menu_dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(etiqueta, &block) ⇒ Menu_dsl

Returns a new instance of Menu_dsl.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/prct11/menu_dsl.rb', line 4

def initialize(etiqueta, &block)
  self.etiqueta = etiqueta
  
  self.titulo     = ""
  self.ingesta    = []
  self.plato      = []
  self.porcentaje = []
  
  if block_given?  
    if block.arity == 1
      yield self
    else
     instance_eval(&block) 
    end
  end
end

Instance Attribute Details

#etiquetaObject

Returns the value of attribute etiqueta.



2
3
4
# File 'lib/prct11/menu_dsl.rb', line 2

def etiqueta
  @etiqueta
end

#ingestaObject

Returns the value of attribute ingesta.



2
3
4
# File 'lib/prct11/menu_dsl.rb', line 2

def ingesta
  @ingesta
end

#platoObject

Returns the value of attribute plato.



2
3
4
# File 'lib/prct11/menu_dsl.rb', line 2

def plato
  @plato
end

#porcentajeObject

Returns the value of attribute porcentaje.



2
3
4
# File 'lib/prct11/menu_dsl.rb', line 2

def porcentaje
  @porcentaje
end

#tituloObject

Returns the value of attribute titulo.



2
3
4
# File 'lib/prct11/menu_dsl.rb', line 2

def titulo
  @titulo
end

Instance Method Details

#ingestas(options = {}) ⇒ Object



26
27
28
29
# File 'lib/prct11/menu_dsl.rb', line 26

def ingestas(options = {})
  ingesta << "#{options[:max]}" if options[:max]
  ingesta << "#{options[:min]}" if options[:min]
end

#platos(options = {}) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/prct11/menu_dsl.rb', line 31

def platos(options = {})
  pl = []
  pl << "#{options[:descPlato]}"      if options[:descPlato]
  pl << "#{options[:descPorcion]}"    if options[:descPorcion]
  pl << "#{options[:ingestaGramos]}"  if options[:ingestaGramos]
  
  plato << pl
end

#porcentajes(options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/prct11/menu_dsl.rb', line 40

def porcentajes(options = {})
  pc = []
  pc << "#{options[:vct]}"            if options[:vct]
  pc << "#{options[:proteinas]}"      if options[:proteinas]
  pc << "#{options[:grasas]}"         if options[:grasas]
  pc << "#{options[:hidratos]}"       if options[:hidratos]
  
  porcentaje << pc
end

#titulos(options = {}) ⇒ Object



22
23
24
# File 'lib/prct11/menu_dsl.rb', line 22

def titulos(options = {})
  titulo << "#{options[:titulo]}"
end

#to_sObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/prct11/menu_dsl.rb', line 50

def to_s
  output = etiqueta
  output << "\n#{'=' * etiqueta.size}\n\n"
  
  output << "#{titulo}"
  output << "(#{ingesta[0]} - #{ingesta[1]}%) \n"

  plato.each_with_index do |plato, index|
    output << "- #{plato[0]}, #{plato[1]}, #{plato[2]}g\n"
  end

  porcentaje.each_with_index do |porcentaje, index|
    output << "V.C.T. | % #{porcentaje[0]}Kcal | #{porcentaje[1]}% - #{porcentaje[2]}% - #{porcentaje[3]}%\n"
  end

  output
end