Class: Dietadsl

Inherits:
Object
  • Object
show all
Defined in:
lib/menu/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Dietadsl

Returns a new instance of Dietadsl.



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

def initialize(&block)
  self.title = ""
  self.ingesta_diaria= []
  self.porcent= []
  self.platos = []
  self.instructions = []
  self.atributo= ""

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

Instance Attribute Details

#atributoObject

Returns the value of attribute atributo.



2
3
4
# File 'lib/menu/dsl.rb', line 2

def atributo
  @atributo
end

#ingesta_diariaObject

Returns the value of attribute ingesta_diaria.



2
3
4
# File 'lib/menu/dsl.rb', line 2

def ingesta_diaria
  @ingesta_diaria
end

#instructionsObject

Returns the value of attribute instructions.



2
3
4
# File 'lib/menu/dsl.rb', line 2

def instructions
  @instructions
end

#platosObject

Returns the value of attribute platos.



2
3
4
# File 'lib/menu/dsl.rb', line 2

def platos
  @platos
end

#porcentObject

Returns the value of attribute porcent.



2
3
4
# File 'lib/menu/dsl.rb', line 2

def porcent
  @porcent
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/menu/dsl.rb', line 2

def title
  @title
end

Instance Method Details

#grupo(text) ⇒ Object



41
42
43
44
# File 'lib/menu/dsl.rb', line 41

def grupo (text)
  grupo = text
  atributo << grupo
end

#ingesta(options = {}) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/menu/dsl.rb', line 46

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

#plato(options = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/menu/dsl.rb', line 54

def plato(options = {})
  plato = ""
  plato << "- #{options[:descripcion]}," if options[:descripcion]
  plato << " #{options[:porcion]}," if options[:porcion]
  plato << " #{options[:gramos]} g" if options[:gramos]
  plato << " #{options[:mlitros]} ml" if options[:mlitros]
  plato << "\n"
  platos << plato
end

#porcentajes(options = {}) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/menu/dsl.rb', line 64

def porcentajes(options = {})
  porcentajes = ""
  porcentajes << "V.C.T | %    #{options[:vct]} kcal | " if options[:vct]
  porcentajes << "#{options[:proteinas]}% - " if options[:proteinas]
  porcentajes << "#{options[:grasas]}% - " if options[:grasas]
  porcentajes << "#{options[:hidratos]}%" if options[:hidratos]
  porcent << porcentajes
  
end

#titulo(text) ⇒ Object



36
37
38
39
# File 'lib/menu/dsl.rb', line 36

def titulo (text)
  titulo = text
  title << titulo
end

#to_sObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/menu/dsl.rb', line 20

def to_s
  
  if atributo != ""
    output = atributo + "\n"
  else
    output=atributo
  end
  output << title
  output << " #{ingesta_diaria.join()}"
  #output << "\n#{'=' * titulo.size}\n\n"
  output << "\n#{platos.join()}"
  output << "#{porcent.join()}"

  output
end