Class: MenuDiet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ MenuDiet

Returns a new instance of MenuDiet.



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

def initialize(name, &block)
    self.name = name
    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.



6
7
8
# File 'lib/practica6/dieta.rb', line 6

def ingesta
  @ingesta
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/practica6/dieta.rb', line 6

def name
  @name
end

#platosObject

Returns the value of attribute platos.



6
7
8
# File 'lib/practica6/dieta.rb', line 6

def platos
  @platos
end

#porcentajesObject

Returns the value of attribute porcentajes.



6
7
8
# File 'lib/practica6/dieta.rb', line 6

def porcentajes
  @porcentajes
end

#tituloObject

Returns the value of attribute titulo.



6
7
8
# File 'lib/practica6/dieta.rb', line 6

def titulo
  @titulo
end

Instance Method Details

#met_ingesta(options = {}) ⇒ Object



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

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

#met_titulo(name) ⇒ Object



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

def met_titulo(name)
    titulo << name
end

#plato(options = {}) ⇒ Object



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

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

#porcent(options = {}) ⇒ Object



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

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

#to_sObject



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

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

    output
        
end