Class: MenuDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/prct6/dieta.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, &block) ⇒ MenuDSL

Returns a new instance of MenuDSL.



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

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

Instance Attribute Details

#ingestaObject

Returns the value of attribute ingesta.



4
5
6
# File 'lib/prct6/dieta.rb', line 4

def ingesta
  @ingesta
end

#nombreObject

Returns the value of attribute nombre.



4
5
6
# File 'lib/prct6/dieta.rb', line 4

def nombre
  @nombre
end

#platosObject

Returns the value of attribute platos.



4
5
6
# File 'lib/prct6/dieta.rb', line 4

def platos
  @platos
end

#porcentajesObject

Returns the value of attribute porcentajes.



4
5
6
# File 'lib/prct6/dieta.rb', line 4

def porcentajes
  @porcentajes
end

#tituloObject

Returns the value of attribute titulo.



4
5
6
# File 'lib/prct6/dieta.rb', line 4

def titulo
  @titulo
end

Instance Method Details

#ingest(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/prct6/dieta.rb', line 27

def ingest(options = {})
    ing = []
 
    if (options[:min] && options[:max])
        ing << options[:min]
        ing << options[:max] 
    else
        ing << options[:max]
    end
    
    ingesta << ing
    
end

#plato(options = {}) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/prct6/dieta.rb', line 41

def plato(options = {})
    dish = []
    dish << "#{options[:descripcion]}"
    dish << "#{options[:porcion]}"
    dish << "#{options[:gramos]}"
    
    platos << dish
end

#porcent(options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/prct6/dieta.rb', line 50

def porcent(options = {})
    por = []
    por << "#{options[:vct]}"
    por << "#{options[:proteinas]}"
    por << "#{options[:grasas]}"
    por << "#{options[:hidratos]}"
    
    porcentajes << por
    
end

#title(name) ⇒ Object



22
23
24
25
# File 'lib/prct6/dieta.rb', line 22

def title(name)
   aux = name
   titulo << aux
end

#to_sObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/prct6/dieta.rb', line 61

def to_s
    output = nombre
    output << "\n#{'=' * nombre.size}\n\n"
    output << "#{titulo} "
    ingesta.each do |ing|
        output << "#{ing}\n"
    end
    
    platos.each do |dish|
       output << "- #{dish[0]}, #{dish[1]}, #{dish[2]}g\n" 
    end
    
    porcentajes.each do |por| 
        output << "V.C.T. | %   #{por[0]} kcal | #{por[1]}% - #{por[2]}% - #{por[3]}%\n"
    end

    output
        
end